If I write char * p = "Welcome". I can see the address for p. But what's the address for the string i.e at which address Welcome stored?
If I write again char *s = "Welcome". p and s will point to same address?
In a debugger, if you inspect p
, you will see the address of the string.
&p
is the address of p
itself.
And no, p
and s
are not guaranteed to point to the same address, but they might.
"Welcome" is string constant and it is stored in read only data section of memory but pointer p is created in stack which points to this string literal
String constant "Welcome" often are putted in "read-only-data" section of memory. Here are good explanations about: String litereals where do they go and data segment
you can find the address of string constant "Welcome" by
printf("%p",p);
If I write again char *s = "Welcome". p and s will point to same address?
Maybe same string constant are putted in the same address, maybe not.