char a[] = "hello";
char *p = "world";
p = &a[1]; /* no 1, valid */
p[1] = &a[1]; /* no 2, invalid*/
p[1] = *a; /*no 3, invalid*/
a= p /* no 4, invaild */
In C, I thought a[] and *p was the exactly the same thing.
But, as the no 1 and 4 shows I found that you can't assign it to array name like a, when you can assign it to p since it's a pointer.
Is this the only difference between declaring string array in two different ways?
Having said that, if you can assign it to the pointer, why no 2 and no 3 are invalid?
Thank you.
p[1]?sizeof(a)is 6 which it is the size of the array "hello" (5) plus null char '\0' (1).sizeof(p)is 8 which is the size of a pointer on a 64bit architecture (8 bytes * 8 bits = 64 bits)