-2
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?

alk
  • 69,737
  • 10
  • 105
  • 255
pupu007
  • 149
  • 1
  • 10

1 Answers1

2

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?

Community
  • 1
  • 1
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208