Reputation: 27210
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 ?
Upvotes: 9
Views: 7134
Reputation: 471199
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)
Upvotes: 10
Reputation: 182619
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.
Upvotes: 9