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

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to