sizeof(char[])
returns the number of bytes in the string, i.e. strlen()+1
for null-terminated C strings filling the entire array. Arrays don't decay to pointers in sizeof
. str
is an array, and the string has 25 characters plus a null byte, so sizeof(str)
should be 26. Did you add a space to the value?
The size of a pointer is of course always determined just by the machine architecture, so both instances of p
are 8 bytes on 64-bit architectures and 4 bytes on 32-bit architectures.
In function arguments, arrays do decay to pointers, so you're getting the same result that you get for a pointer. Therefore, the following definitions are equivalent:
void foo(char s[42]) {};
void foo(char s[100]) {};
void foo(char* s) {};