Are string literals guranteed to be adjacent to each other in memory?

c

Solution

No, string literals are stored wherever your compiler fancies. The fact that you declared two of them in consecutive lines is irrelevant. You can make no assumptions about where the compiler will store them.

The compiler can do all sorts of things. For example, if you write the following code

printf("hello");
printf("hello");

then the compiler is perfectly at liberty to create only a single literal. Or not.

Problem

Is it guranteed that the string literals are stored adjacent in the memory? Therefore does the below necessarily get an output `hellohello` ``` printf(3 + "%d"); printf("hello"); ```

Original source