The length of an array is output here. There are several ways to determine the length of an array.
#include <iostream>
using namespace std;
int main () {
int numbers[] = {2, 6, 4, 8, 1};
int arrayLength = sizeof numbers / sizeof numbers[0];
for(int i = 0; i < arrayLength; i++) {
cout << numbers[i] << endl;
}
}
2
6
4
8
1
#include <iostream>
using namespace std;
int main () {
int numbers[] = {2, 6, 4, 8, 1};
int arrayLength = end(numbers) - begin(numbers);
cout << "Length of array: " << arrayLength << endl;
for(int i = 0; i < arrayLength; i++) {
cout << numbers[i] << endl;
}
}
Length of array: 5
2
6
4
8
1