Help required- segmentation error

can anybody please help me find out which part of the code mentioned below
is probably causing a segmentation error.I would be grateful enough.:slight_smile:

#include <stdio.h>      
 int main() 
{
	int t,i;
	long int n,sum,j,sindex,eindex,arr[10000001],currentsum;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
	    scanf("%ld %ld",&n,&sum);
	    sindex=1;
	    eindex=0;
	    currentsum=0;
	    for(j=1;j<=n;j++)
	    {
	        scanf("%ld",&arr[j]);
	        currentsum+=arr[j];
	        eindex++;
	        while(currentsum>sum)
            {
                currentsum-=arr[sindex];
                sindex++;
            }
	        if(currentsum==sum)
	        printf("%ld %ld",sindex,eindex);
	        
            
	    }if(sindex==n+1)
	    printf("-1");
	    
	}
	return 0;
    }

Because you are declaring a huge array inside main()
Declare it outside of main and i think it would work
:slight_smile:

1 Like

thanks a lot.:slight_smile:

Is it working now ?

yes.:100:

1 Like