sometimes we use this type of code in our c programming.
char *p = "Sam";
Here the address of constant character string "Sam" is going to be stored in char pointer p. now here
i want to ask where the Sam is going to be stored ?
The standard doesn't specify this. Typically the string literal ("Sam"
) will be stored in the data section, in a read-only page.
As for p
itself, it depends on whether it is automatic or static.
The string "Sam" will usually be stored in global memory in the same region as the global constants.
However, if you did this:
char p[] = "Sam";
Then it would be on the stack instead. (as an array initializer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With