Check out example codes for "build a prefix array cpp". It will help you in understanding the concepts better.

Code Example 1

void fillPrefixSum(int arr[], int n, int prefixSum[]) 
{ 
    prefixSum[0] = arr[0]; 
  
    // Adding present element 
    // with previous element 
    for (int i = 1; i < n; i++) 
        prefixSum[i] = prefixSum[i - 1] + arr[i]; 
}

Learn ReactJs, React Native from akashmittal.com