From the C Standard (6.4.5 String literals)
7 It is unspecified whether these arrays are distinct provided their
elements have the appropriate values. If the program attempts to
modify such an array, the behavior is undefined.
So the compiler may store identical string literals either as one string literal or as separate string literals. Usually compilers provide an option that allows the user to select how string literals will be stored.
It seems that the compiler you are using stores identical string literals as one string literal by default. You may imagine the situation the following way
char string_literal_hello[] = { 'h', 'e', 'l', 'l', 'o', '\0' };
int main(void)
{
char *l = string_literal_hello;
char *m = string_literal_hello;
if (l == m)
printf("true");
}
Thus the both pointers l
and m
point to the same character 'h'
of the character array string_literal_hello
that the compiler stores in a string literal pool.