Posts

Showing posts from August, 2013

Segmentation Fault : behind the code

Segmentation fault Segmentation fault (core dumped) Did you just look at your laptop and said, "This is it buddy, don't check my patience, you are going to get hurt !!!" . If you are in this situation, then just try to understand the concept behind segmentation fault and forget the headache ;-) Segmentation fault is the exception which occurs when a program tries to access an invalid memory.  In simple words, it means accessing a memory which does not belong to you or you do not have authorization to access it.  To resolve this, you must know about GNU Debugger(GDB) , but if you are SHORT OF TIME  then first try following example: 1  #include<stdio.h> 2  int main() 3  { 4   int *p; 5   *p= 7; 6   printf("Output = %d\n",*p); 7  }  If we run this program, we will get Segmentation fault: user@gene-laptop:~$ gcc -g segment.c user@gene-laptop:~$ ./a.out Segmentation fault (core dumped) The -g option in gcc is used so that later