Why is size of this char variable equal 1?
int main(){
char s1[] = \"hello\";
fprintf(stderr, \"(*s1) : %i\\n\", sizeof(*s1) ) // prints out 1
}
NOTA: the original question has changed a little bit at first it was: why is the size of this char pointer 1
sizeof(*s1)
is the same as
sizeof(s1[0])
which is the size of a char
object and not the size of a char
pointer.
The size of an object of type char
is always 1
in C.
To get the size of the char
pointer use this expression: sizeof (&s1[0])