How cumsum[-1] will be evaluated

Sir in the video the statement currentsum=cumsum[ j ]-cumsum[ i-1].
Can you explain that when the value of i=0 how the above statement will be evaluated

hello @jsn853
this should give run error becuase for i=0 , i-1 will be -1 and accessing negative index should give run error but some new compiler dont give any error. accessing negative index is bad practice and one should avoid doing it.

add a simple if statement to handle this case separately.
i.e if i==0 then currentsum=cumsum[j].

ok got it.
but in the video prateek bhaiya got the right answer even after excluding the if statement

some comilers dont show any error they simply take 0 as their value.

ok got it
bhaiya thanks for the instant reply

you can also modify the garbage value at *(cummulativeSum-1) this memory address to zero.i.e.
int cummulativeSum[size];
*(cummulativeSum-1)=0;
for(int i=0; i<size; i++) cummulativeSum [i]=cummulativeSum [i-1] + arr[i];

It works fine.