Why I am getting a runtime error SIGSEGV in the problem? Where I am going wrong?
This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an array element out of bounds, or using too much memory.
Some things for you to try:
Make sure you aren’t using variables that haven’t been initialised. These may be set to 0 on your computer, but aren’t guaranteed to be on the judge.
Check every single occurrence of accessing an array element and see if it could possibly be out of bounds.
Make sure you aren’t declaring too much memory. 64 MB is guaranteed, but having an array of size [10000][10000] will never work.
Make sure you aren’t declaring too much stack memory. Any large arrays should be declared globally, outside of any functions - putting an array of 100000 ints inside a function probably won’t work.
//why i was getting SIGSEGV??
//for this question CodeChef: Practical coding for everyone
//please help n explain
for this solution CodeChef: Practical coding for everyone
why di i get reutime error for given problem
#include<stdio.h>
#include<stdlib.h>
#define size 65535
int main()
{
long n,k,j,t[size],i=0,count=0;
scanf("%ld %ld",&n,&k);
while(i<n)
{
scanf("%ld",&t[i]);
printf("\n");
if(t[i]%k==0)
count++;
i++;
}
printf("%ld\n",count);
}
why do i get SIGSEVG
can anyone help me…why i am getting SIGSEVG error in this PeQwg9 - Online C Compiler & Debugging Tool - Ideone.com
thanks in advance
can anyone help me…why i am getting SIGSEVG error in this PeQwg9 - Online C Compiler & Debugging Tool - Ideone.com
thanks in advance
#include<stdio.h>
main()
{
long long t=0,i=0,j=0,temp=0,a[10000];
scanf("%lld",&t);
for(i=0;i<t;i++)
scanf("%lld",&a[i]);
for(i=0;i<t-1;i++)
{
for(j=0;j<t-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<t;i++)
printf("%lld\n",a[i]);
}
A segfault basically means you did something bad with pointers. This is probably a segfault:
char *c = NULL;
…
*c; // dereferencing a NULL pointer
Or this:
char *c = “Hello”;
…
c[10] = ‘z’; // out of bounds, or in this case, writing into read-only memory
Or maybe this:
char *c = new char[10];
…
delete [] c;
…
c[2] = ‘z’; // accessing freed memory
Same basic principle in each case - you’re doing something with memory that isn’t yours.
Adobe Systems is hiring Software Engineers
CTC:- 8-30 Lac, Exp:- 0-8 Years, Bangalore
Apply Here:- http://jobsiit.com/jobs/view/1876/Adobe-Systems/Software-Engineer