Friday, 23 August 2013

Sizes of arrays declared with pointers

Sizes of arrays declared with pointers

char c[] = "Hello";
char *p = "Hello";
printf("%i", sizeof(c)); \\Prints 6
printf("%i", sizeof(p)); \\Prints 4
My question is, why do these print different results? Doesn't c[] also
declare a pointer that points to the first character of the array (and
therefore should have size 4, since it's a pointer)?

No comments:

Post a Comment