Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Regarding Head First C..How to acces string literal?

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
1 person has
this question
+1
Reply
  • Hello Arpit,

    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 booktech@oreilly.com or call them at:

    1-800-889-8969
    or
    1-707-827-7019 (outside the USA)
    7:30 am to 5:00 PST

    Kind regards,
    Paul Fichera
    Customer Service Representative
    O'Reilly Media
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hi Arpit,

    Here is the response from one of the authors to your question:

    -----

    Hello Arpit,

    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[0] = '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.

    HTH

    David Griffiths
    Co-author, Head First C
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly