linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krishna Mohan <gkmohan@rocsys.com>
To: LinuxC <linux-c-programming@vger.kernel.org>
Subject: pointer initialization of string constant
Date: 23 Jan 2005 11:56:11 +0530	[thread overview]
Message-ID: <1106461572.1122.1.camel@KrishnaMohan> (raw)

Dear All, 
Plz see the following code. It gives segmentation fault. ofcourse, it's
right as char *ptr = "abc" sets pointer to the address of the "abc" 
string (which may be stored in read-only memory and thus unchangeable).
My doubt : when i run gdb and execute p ptr either after or before
printf, pbc has been displayed. I'm getting segmentation fault only at
the end, it seems, because when i run ./a.out  "pbc is not displayed"
but prompted segmentation fault error. why is it so? How does
segmentation fault raises, though pointer-pointing contents has been
changed & even displayed using gdb. Will U plz explain in detail
(internals).

main()
{
        char *ptr = "abc";
        ptr[0] = 'p';
        printf("%s\n",ptr);
}

Thanx in advance. 
Krishna Mohan


             reply	other threads:[~2005-01-23  6:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-23  6:26 Krishna Mohan [this message]
2005-01-23 12:45 ` pointer initialization of string constant Progga
2005-01-23 13:36   ` Krishna Mohan
2005-01-24  5:49     ` how to implement tail -n Venkatesh Joshi
2005-01-24  6:30       ` Eric Bambach
2005-01-25 14:10         ` Robert Lorentz
2005-01-24 19:26       ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1106461572.1122.1.camel@KrishnaMohan \
    --to=gkmohan@rocsys.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).