In the following code:
char *p = "Linux";
Is the memory for "Linux" on the stack or the read only segment of the program?
Refer to question 9 in the article 12 Interesting C Interview Questions and Answers.
Thanks.
In the following code:
char *p = "Linux";
Is the memory for "Linux" on the stack or the read only segment of the program?
Refer to question 9 in the article 12 Interesting C Interview Questions and Answers.
Thanks.
The implementation is free to store it wherever it wants. It's a constant, so it can be in read-only memory, but it is not required to be.
My instructor for C programming always says its on the stack, hence the doubt.
He probably means the pointer. Consider:
char *p = "Linux";
p = "Rules";
In the second line, something changed from pointing to "Linux" to pointing to "Rules". That thing that just changed is on the stack.
p(the pointer) is on the stack.