C++ Code Example: passing array to function

Method for doubling the elements of an integer array. Due to the referent passing, the values of the array change in the main program.

#include <iostream>
using namespace std;

void doubles(int array[], int length) {
    for (int i = 0; i < length; i++) {
        array[i] = 2 * array[i];
    }
}

int main() {
    int length, myArray[] = {6, 12, 30, 14, 66, 6, 7};

    length = sizeof myArray / sizeof myArray[0];
    doubles(myArray, length);

    cout << "values from array doubled: " << endl;
    for (int i = 0; i < length; i++) {
        cout << myArray[i] << " ";
    }

    return 0;
}
Output
values from array doubled: 
12 24 60 28 132 12 14