I started learning C and got a question that I could not find the answer to.
When I initialize a random string with
char *str1 = "Big";
printf("size of str1: %ld\n", sizeof(str1));
it gives me the size 8 (bytes) when I do sizeof(str1)
, which does not makes sense to me.
When I initialize a random string with
char str2[] = "Big";
printf("size of str2: %ld\n", sizeof(str2));
it gives me the size 4 (bytes) when I do sizeof(str2)
, which DOES make sense to me because three chars 'B'
, 'i'
, 'g'
, and '\0'
.
How come the first one gives me the size 8?