How does the compiler allocate space for char *

Hello all ,
question about char pointer.
when we declare this variable.
char *word = "Hello, world" ;
how does the compiler allocate space for this string literal.
does it implicitly call malloc/new to allocate the space of this string literal then assign it to word?
I am not sure exactly.
Thank you.
Last edited on
String literals ( like "Hello, world" ) have static storage duration.
static storage duration. The storage for the object is allocated when the program begins and deallocated when the program ends. http://en.cppreference.com/w/cpp/language/storage_duration

The type of a string literal is array of n const char; type of "Hello, world" is const char[13].
This would generate an error with a conforming compiler: char *word = "Hello, world" ;
This would be fine: const char* word = "Hello, world" ;
Topic archived. No new replies allowed.