top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is meant by segmentation fault or memory fault in C?

+1 vote
485 views
What is meant by segmentation fault or memory fault in C?
posted Jan 22, 2015 by Balu

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+3 votes

segmentation fault is a run-time error.
Whenever our program trying to access the memory location that we are not suppose to use then our program will get segmentation fault.
Ex:

#include<stdio.h>
main()
{
int *p;
printf("%d\n",*p); \\print the value present at that unknown memory location
}

-->In 1st step we have defined a pointer, pointer contains a garbage value.
-->In 2nd step we are printing the value which is present at unknown address that we are not suppose to do.

so it will give segmentation fault.

answer Jan 23, 2015 by Chirag Gangdev
+2 votes

Segmentation fault is a fault that occurs because of illegal/invalid memory access.

Illegal memory access means, When a program tries to access a memory location that is not allowed or when a program tries to access a memory location in a way that is not allowed.

answer Jan 23, 2015 by Shivaranjini
Similar Questions
0 votes

Following is my code and getting segmentation fault. Please help

#include<stdio.h>
#include<string.h>
main()
{
    char *p,str[100]="Hi, How Are You, Fine, Thank You";
    p=strtok(str,",");
    printf("%s\n",p);
    while(p != NULL)
    {
        p=strtok(NULL,",");
        printf("%s\n",p);
    }
}

O/p is:
Hi
How Are You
Fine
Thank You
and then Segmentation fault.

+4 votes

I have written print("%s", __LINE__); I get crashed. Can someone please explain why it is happened ?

0 votes

How can we debug the segmentation fault in a program which has been compiled without "-g" option?

+5 votes

What is meant by FSM in c and what is the uses and where we are using can anyone explain with an Example?

...