String Constant C

I wonder string constant exists permanently or temporary.

For example,

printf("hello, world");

the function printf access to it is through a pointer. Does it mean storage is allocated for the string constant to exist permanently in memory? :confused:

The duration of objects in a C program varies.

"Hello World" is a constant and the memory persists for the duration of the program. The pointer is only visible from the function it was called from, the way you have coded it.

For example,

int *pointer = "Hello, World";

Is the string constant available until the pointer variable as an automatic variable is discarded?

String literals are static objects so they are in existence as long as the program is running. As "pointer" is an automatic variable it is discarded upon exit from the block in which it is defined but the string literal will still be in memory but you wont have a handle for accessing it anymore. Automatic variables are on the stack segment while static objects are in the text segment or the readonly portion of the data segment and yes the compiler automatically allocates storage for them without the programmer having to do anything...

Yes they are embedded in the code, if you do a strings(1) on your program you will see them.