Array/Pointer confusion
c++
Solution
Change `output[n]` to `output[i]` instead, you're not writing to any index in the array since `output[7]` is out of bounds. `i` is your loop counter not `n`
Problem
Why does the following code print out `"0 0 0 0 0 0 0 "`? I was expecting `"1 3 6 10 15 21 28 "`. ``` #include <iostream> using namespace std; void PrefixSum(float * input, float * output, int n){ float sum = 0; for (int i=0;i<n;i++){ float value = input[i]; sum += value; output[n] = sum; } } int main(int argc, const char * argv[]) { float input[] = {1,2,3,4,5,6,7}; float output[] = {0,0,0,0,0,0,0}; PrefixSum(input, output, 7); for (int i=0;i<7;i++){ cout << output[i] << " "; } return 0; } ```