I have a question about how compiler stores C string?Here is some pieces of code:
#define STRING_MACRO "macro"
const char * string_const = "w";
int main(void){
printf("%u\n", sizeof(STRING_MACRO));
printf("%u\n", sizeof(string_const));
return 0;
}
output:
6
4 -- my system is x86, so it is 4
So I am confused about how compiler stores c string?Is it the same between macro style and value style?
I think most people misunderstanding my question.So I tried another code by myself.
#define TEST "a"
int main(void)
{
char hello[] = "aa";
char (*a)[10] = &hello;
printf("%u\n", sizeof(TEST));
printf("%u\n", sizeof(hello));
printf("%u\n", sizeof(*a));
return 0;
}
output:
2
3
10
So I got a conclusion the compiler store c string of macro style in char[] type, not char * type.