[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: structures and classes Up: Aggregation Previous: Aggregation

arrays

Variables of the same type can be put into arrays.

char letter[50];

defines an array of 50 characters, letter[0] being the 1st and letter[49] being the last character. C++ arrays have no subscript checking; if you go off the end of an array C++ won't warn you.

Multidimensional arrays can be defined too. E.g.

char values[50][30][10];

defines a 3D array. Note that you can't access an element using values[3,6,1]; you have to type values[3][6][1].

The Standard Library offers various alternatives (vector, for example) which are often preferable to the basic arrays described above because



Tim Love
2001-07-05