c - Why does the "Hello" inside the string array have a size 4? -
the code in question:
#include <stdio.h> int main(void) { char *a[10] = {"hi", "hello", "how"}; printf("%d\n", sizeof(a)); printf("%s\n%s\n%s\n", a[0],a[1],a[2]); printf("%d\n%d\n%d\n", sizeof(a[0]),sizeof(a[1]),sizeof(a[2])); printf("%d", sizeof("hello")); return 0; } output:
40 hi hello how 4 4 4 6 i have no idea why happening , looked reference sizeof on cppreference. still have no clue why returning 4 "hello" when should need 6 store it.
it print size of pointer not string content itself. of size printed 4 bytes.
Comments
Post a Comment