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.