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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.
He probably means the pointer. Consider:
In the second line, something changed from pointing to “Linux” to pointing to “Rules”. That thing that just changed is on the stack.