Q64 What is segmentation fault?

The segmentation fault is a programming error, means the program is trying to access an invalid memory location or memory which does not exist.

See an example program of segmentation fault:

#include<stdio.h>

int main()

{

        int *num;

             /* This line will give segmentation fault */

             /* Accessing pointer variable ‘num’ without allocating memory */

        *num = 10;

        return 0;

}

Output:

$ ./a.exe

Segmentation fault (core dumped)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.