Why we use negative index of csum arrray. csum[-1]

in the loop
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
currentsum=0;
cout<<j<<" "<<i-1<<endl;
currentsum=csum[j]-csum[i-1];
cout<<currentsum<<endl;
if(currentsum>maxsum)
{
maxsum=currentsum;
left=i;
right=j;
}
}
}

when i=0,j=i;
currentsum=csum[j]-csum[i-1];
so i-1<0 because i=0
so how can we use csum[-1]??

Here value of csum[-1] will be considered as 0. C++ compiler will assign the value at negative index as 0. You can check that in the ide.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.