int main (void) /*case :1 */
{
int *ptr;
*ptr = 4;
return 0;
}
It is giving segmentation fault. in this case ptr is initialized with 0 address. I checked with gdb tool
int main (void) /* case2 */
{
int *ptr;
*ptr = 4;
printf ("%d", ptr);
return 0;
}
it is not giving segmentation fault. output = 4;
int main (void) /* case3 */
{
int *ptr;
ptr++;
*ptr = 4;
printf ("%d", ptr);
return 0;
}
again it is giving segmentation fault. in case 2 and case 3 ptr value is "0xb76f7000" I have checked maps file of the process this address belong to library file. cat /proc/10489/maps
08048000-08049000 r-xp 00000000 08:06 788694 /home/durga/app
08049000-0804a000 r--p 00000000 08:06 788694 /home/durga/app
0804a000-0804b000 rw-p 00001000 08:06 788694 /home/durga/app
b754c000-b754d000 rw-p 00000000 00:00 0
b754d000-b76f5000 r-xp 00000000 08:01 132823 /lib/i386-linux-gnu/libc-2.19.so
b76f5000-b76f7000 r--p 001a8000 08:01 132823 /lib/i386-linux-gnu/libc-2.19.so
b76f7000-b76f8000 rw-p 001aa000 08:01 132823 /lib/i386-linux-gnu/libc-2.19.so
b76f8000-b76fb000 rw-p 00000000 00:00 0
b7711000-b7715000 rw-p 00000000 00:00 0
b7715000-b7717000 r--p 00000000 00:00 0 [vvar]
b7717000-b7719000 r-xp 00000000 00:00 0 [vdso]
b7719000-b7739000 r-xp 00000000 08:01 132826 /lib/i386-linux-gnu/ld-2.19.so
b7739000-b773a000 r--p 0001f000 08:01 132826 /lib/i386-linux-gnu/ld-2.19.so
b773a000-b773b000 rw-p 00020000 08:01 132826 /lib/i386-linux-gnu/ld-2.19.so
bfb59000-bfb7a000 rw-p 00000000 00:00 0 [stack]