void f()
{
char *c = \"Hello World!\"
}
Where is the string stored? What\'s the property of it? I just know it is a constant, what else? Can I
The string is stored in the data area of the program. This is completely compiler, executable format, and platform dependent. For example, an ELF binary places this in a different location than a Windows executable, and if you were compiling for an embedded platform this data might be stored in ROM instead of RAM.
Here's an illustration of the layout of the ELF format:
Your string data would most likely be found in the .data
or .text
sections, depending on compiler.
You can certainly return it from inside the function body. Just check with your implementation to verify that it is random access, as many implementations won't let you overwrite it.
§2.14.15 String Literals, Section 7
A narrow string literal has type “array of n const char”, where n is the size of the string as defined below, and has static storage duration.