Why do I get a SIGSEGV?

please help , why do i get RUNTIME ERROR (SIGSEGV)
https://www.codechef.com/viewsolution/9965435

https://www.codechef.com/viewsolution/9994477
why do i get SIGSEVG

@thepranay14 you are getting segsigv because in question the upper limit of n i.e the number of elements in array p is 100000 but you are storing just 9997. when you got the value of n from stdin then it may contain a value of 100000 and your for loop will for(i=0;i<n;i++){ scanf("%d",&p[i])} will expect the size of p[] to be around 100000. this is the reason you are getting a sigsegv

why do i get a runtime error sigsegv for this problem? pls help.#include<stdio.h> int main() { int k, n; while(n<=10000000&&k<=10000000) scanf("%d", &n); scanf("%d", &k); int t[n]; int i; while(i<n&&t[i]<=1000000000) { scanf("%d\n", &t[i]); i++; } int count = 0; for (i = 0; i < n; i++) { if (t[i] % k == 0) count = count + 1; } printf("%d", count); }

Why I am getting SIGSEGV error on TSORT problem. I am using C and here is my Solution

why do i get SIGSEGV in this code please help me…
https://www.codechef.com/viewsolution/10061505

please help why do i get sigsegv in this code https://www.codechef.com/viewsolution/10091819

#include<stdio.h>
int main()
{
int r,i,j,k,l,p,q,x;
int n,m,T;
int B[n],A[n-m];
scanf("%d",&T);
for(k=0;k<T;k++)
{
scanf("%d%d",&n,&m);
for(r=0;r<n;r++)
{B[r]=0;
}

 	 for(l=0;l<m;l++)
 	 {
 	 	 scanf("%d",&x);
 	 	 B[x-1]=1;
	  }
	  
for(i=0,j=0; i<n,j<n-m; i++)
{
	 if(B[i]==0)
	 A[j++]=i+1;
	 
 }
 
 for(q=0;q<n-m;q=q+2)
 {printf("%d ",A[q]);
  A[q]=0;
	   }	
printf("\n");	   
		     
for(p=0;p<n-m;p++)
	  {
	  	if(A[p]!=0)
	  	printf("%d ",A[p]);
	  }
	printf("\n");	  
	  
	  
	   }
	   return 0;

}

why am i getting this error here???pls help

Why are my programs getting runtime error (SIGSEV) during submissions but run well in all IDEs I’ve tried?
I’m pretty sure it’s not a case of out-of-range array access. What are the other possible faults?

please check this this code works fine on codechef ide ,ideone.com but every time when i am submitting i am getting runtime error SIGSEGV https://www.codechef.com/viewsolution/10443904

  1. I do not quite understand why there are so many people have posted their own questions as answers for this question. Probably, this isn’t well moderated or there is something that I do not understand.
  2. Since, there is no code provided in the question the reason for getting SIGSEGV could not be determined. I am surprised that this old thread has 61 answers when actually there is no relevant information.

Refer Code Chef Wiki about status codes

why m getting SIGSEGV RUNTIME ERROR for problem https://www.codechef.com/problems/LCOLLIS solution is https://www.codechef.com/viewsolution/10610834

SIGSEV error pops up due to a segmentation fault

Possible reasons for segmentation fault are :

  • One of the array indices you used would’ve been an invalid index . This means that at some point of execution , your program uses a value for the array index that is either more than the size of the array or less than 0
  • When you try to dereference a pointer with NULL value
  • When you declare an array of a very huge size . In this case the compiler itself can’t handle the array . Hence it pops out segmentation fault

Try adhering to all of the specifications as mentioned by the admin

Also , this link may help you

getting SIGSEV onthis piece of code which is from the beginner fctrl problem

#include
using namespace std;
int main()
{
int num,n=1,zeroes=0,power=5;
cin>>num;
int i,j,k,arr[1000],res[1000];
for(i=0;i<num;i++)
{
cin>>arr[i];
}
for(j=0;j<num;j++)
{
zeroes=0;
power=5;
while((arr[j]/power)>0)
{
zeroes+=(arr[j]/power);
n++;
power*=5;
}
res[j]=zeroes;
}
for(k=0;k<num;k++)
cout<<res[k]<<endl;
return 0;
}

please help tried to write a very precise piece of code but it seems not to be working help;

why do i get SIGSEVAG for this code ?
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int m,n,i,indices,count=0;
cin>>n>>m;
int a[n]={0};
while(m–){
cin>>indices;
a[indices-1]=1;
}

	  for(i=0;i<n;i++){
	  	if(a[i]!=1){
		  
	  	count++;
	  	if(count%2==0&&count!=0)
	  	a[i]=3;
	  	if(count%2==1)
	  	a[i]=4;		     
	  }
}
	  
	for(i=0;i<n;i++){
		if(a[i]==4)
		cout<<i+1<<" ";

}
cout<<endl;
for(i=0;i<n;i++){

		if(a[i]==3)
		cout<<i+1<<" ";
	}
	cout<<endl;
}
return 0;

}

life saver!

@vineeta1995
.Condition if(t[I]℅k==0)
Will give run time error if value of k=0;

@ankittt_jain you have declared array a[n]
If the value of n goes above 10^6 then you will get run time error.

please help why do i get SIGSEVG for this code
https://www.codechef.com/viewsolution/10818136