I am unable to determine the cause of the error .
declaring function prototype as :
long long int myfunc(long long int,long long int);
A global array has been declared as :
long long int a[50000];
calling function myfunc() by copying parameters start and end like :
num=myfunc(start,end);
Function Definition :
long long int myfunc(long long int start,long long int end)
{
long long int x=0;
int i=0;
if((start<0)||(start>10000)||(end>10001)||(end<0))
return 0;
for(i=start;i<=end;i++)
{
x = x+ a[i];
}
return x;
}
By Commenting out the loop in the function I am able to get WC as result but in all other cases its Runtime Error ( SIGSEGV) . The above function is the only place where the array is being accessed. Program working fine on my system ( tested with boundry conditions) !
Reasons of SIGSEGV-
2 Likes
the problem might be with βiβ also. try declaring βiβ with long long int data type and see if it works.
Yes you are checking that start and end are inside βintβ range :). but just try , programs some times behave differently .
This is a suggestion not a solution.
I am aware of the reasons for SIGSEGV as can be seen in the FAQ . Just not clear how an array is being accessed out of bound here or how sizeof(a)> 64 M [ where a : long long int a[50000])