When i is equal to zero, currentSum = cumsum[j] - cumsum[ - 1] , in this case we are trying to access an index which actually does not exist, then why aren’t we getting an error ? … Or if in case c++ doesn’t throw an exception for such an action, then what is the value being returned for cumsum[-1] ? because if it were to be some garbage value (as mentioned in intro to arrays) then our final answer should turn out to be wrong in most of the cases.