Why is size of this char variable equal 1?
int main(){
char s1[] = \"hello\";
fprintf(stderr, \"(*s1) : %i\\n\", sizeof(*s1) ) // prints out 1
}
sizeof(*s1)
means "the size of the element pointed to by s1
". Now s1
is an array of char
s, and when treated as a pointer (it "decays into" a pointer), dereferencing it results in a value of type char
.
And, sizeof(char)
is always one. The C standard requires it to be so.
If you want the size of the whole array, use sizeof(s1)
instead.