C++ Code Example: sum up all numbers from an array

In this example, each array element is added to the variable sum.

#include <iostream>
using namespace std;

int main() {
    int numbers[] = {33, 431, 41, 76, 83, 99, 46, 9, 22};
    int sum = 0;
    int arrayLength = end(numbers) - begin(numbers);

    for (int i = 0; i < arrayLength; i++) {
        sum += numbers[i];
    }

    cout << "Sum of all elements in the array is: " << sum;

    return 0;
}
Output
Sum of all elements in the array is: 840