char *str1 = "pupupupu";
char str2[] = "pupupupu";
printf("%s\t%d\n", str1, (int)sizeof(str1));
printf("%s\t%d\n", str2, (int)sizeof(str2));
Output:
pupupupu 8
pupupupu 9
My question: Why are the two output sizes different?
sizeof(str1)
is size of char pointer where as sizeof(str2)
gives size of array that is string length (pupupupu
) + 1
Read my this answer, its not exactly same but help you much: What does sizeof(&arr) returns?