#include <stdio.h>
int main(void) {
int arr[10];
arr = "Hello";
printf("%s",arr);
return 0;
}
The above code shows compiler error:
t.c: In function ‘main’:
t.c:5:9: error: assignment to expression with array type
arr = "Hello";
^
t.c:6:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%s",arr);
^
Whereas the below code works fine.
#include <stdio.h>
int main(void) {
char arr[10] = "Hello";
printf("%s",arr);
return 0;
}
Both look identical to me. What am I missing here?