About Arrays in C++
The array data structure in C++ is a fixed-size collection of elements of the same type referenced by an integer index. C++ supports several types of arrays:
- One-dimensional array - inherited from the C language
- Multidimensional array, i.e. "arrays of arrays" - inherited from the C language
- Array class template - feature of C++
Example: Array of one dimensional bowling scores array and average calculation
#include
using namespace std;
int scores [] = {125, 133, 166, 123};
int x, total=0, average=0;
int main ()
{
for ( x=0 ; x<4 ; ++x )
{
total += scores[x];
}
average = total / x;
cout << "Bowling average: " << average;
return 0;
}
Output:
Bowling average: 136