Where is memory allocated with a const char pointer?

c, c++, memory

Solution

It's not allocated. It's generally stored in your program's code segment or on the stack That's up to the compiler. Either way, it points to a null-terminated array of characters.

Problem

Possible Duplicate: Is a string literal in c++ created in static memory? C++ string literal data type storage In this code: `const char * str = "hello world";` If I understand correctly a pointer is 4 or 8 bytes, which I guess would be allocated on the stack. But where is the memory for the "hello world" allocated and stored? Or what does `str` point to exactly?

Original source

Related problems