runtime error in c

SIGSEGV(signal 11) - most common, ‘segmentation fault’;
how to remove this error

should not be marked as community wiki

1 Like

This error mostly occurs when you are illegally accessing some memory. Like if you have taken an array a[100], but the test files try to access a[102] then that will imply a SIGSEGV.
Or, if your algorithm itself is trying to illegally access some memory then too, it occurs.

Most of the times you can remove this error by taking a bigger array (to hold all possible values in the domain of the test case variables) OR by observing your algorithm where you are using memory.

Sometimes, a non-zero return value (main()) gives runtime error. So you need to check that too.

For more specific answers, please post the example where you got SIGSEGV, along with your code.

Update:

Talking about this submission http://www.codechef.com/viewplaintext/1948882

On the first look, you should not have printed “Row add” and “Col add”. I have not yet read your code fully. But I expect you to try it again afresh. Good Luck

1 Like

common cause to SIGSEGV error are:



1: using a memory which is out of bound of an array. for example defining a[1000] and using a[1001]


2: using an index which is negative that is for some cases you might go to negative index which may cause SIGSEGV error.like a[-1]


3: you are using a pointer that does not hold any address or value.for example you are defining int *p; and not allocating it by malloc or not initializing to NULL then also it gives SIGSEGV error.


4: you are using a memory and not releasing it after program in C…i am not sure but this may be also.



you can see your code for above stated errors. Happy Coding...
3 Likes

Can someone please help me in debugging as in why the following program giving SIGSEGV on codechef for question Racing Horses(easy problem) though it runs perfectly fine on ideone and codeblocks.
Link of the code : Ua0SZY - Online C Compiler & Debugging Tool - Ideone.com

1 Like

In a dynamic implementation… We are creating nodes but it will be created upto a fixed memory… After that error will come

i am a beginner . i am stuck with segmentation fault.i am pretty sure my code is correct.it worked in turbo C++ editor but it caused an error when i ran it here. can someone correct the segmentation fault in my pgm?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int T,N,t,count[10],i,A[10],C[10],B[10],k=-1;

for(i=0;i<10;i++)
count[i]=0;
scanf("%d",&T);
scanf("%d",&N);
for(t=0;t<T;t++)
{

k++;
for(i=0;i<N;i++)
{

	scanf("%d",&A[i]);
	C[i]=A[i];

}
for(i=0;i<N;i++)
{

	scanf("%d",&B[i]);

}

for(i=0;i<N;i++)
{
	if(A[i]>=B[i])
	{
		++count[k];


	}
	if(i==N-1)
	{
	break;
	}
	A[i+1]=A[i+1]-C[i];

}

}

for(i=0;i<=k;i++)
printf("%d\n",count[i]);

	return 0;

}

1 Like

https://www.codechef.com/viewsolution/14108863
can someone pls tell why i am getting runtime error here?i have checked for all the possibilities mentioned above…but i m stuck.i am a beginner,pls help in this one.
THanks

point number 4 need not imply SIGSEGV

1 Like

i am confused about point 4.but it is good to release memory…anyways thanks for clearing me.

my program is running perfectly in ubuntu but for the same custom input it is showing SIGSEGV in codechef IDE.

Can you tell me the possible errors !!

1 Like