if we declear an array of character and then what about that string literal can we ever acess it?
char *c = "JQK";
"JQK" store in constant memory block and array create a copy in to stack for string to access.so can we access that read only memory via any address otherwise it would be wastage of memory
Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I have forwarded your question on to our Book Tech staff, so they can help you find a solution. If you ever have any questions or issues with the content of a title, you can also contact them directly at email@example.com or call them at:
1-707-827-7019 (outside the USA)
7:30 am to 5:00 PST
Customer Service Representative
Here is the response from one of the authors to your question:
The "c" variable will point directly at the first character in the string
literal, so yes you can access it. However, you should not try to *modify*
the string literal using the "c" variable (e.g. with c = 'L'). String
literals are typically loaded into read-only protected memory, and even
when they're not (for example, in Cygwin) it is bad practice to modify them.
Co-author, Head First C