Whether two different string literals with same content is placed in the same memory location or different memory locations is implementation-dependent.
You should always treat p
and p1
as two different pointers (even though they have the same content) as they may or may not point to the same address. You shouldn't rely on compiler optimizations.
C11 Standard, 6.4.5, String literals, semantics
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.
The format for printing must be %p
:
printf("%p %p", (void*)p, (void*)p1);
See this answer for why.