C++:Accessing an Array

From Progzoo
Jump to navigation Jump to search

You access an array using the square bracket notation.

The first element of array x is x[0]

You can initialise the array to a specific list of values:


[Font] [Default] [Show] [Resize] [History] [Profile]

The last element of array x is x[sizeof x/sizeof *x -1]

The length of the array is sizeof x/sizeof *x

You divide the size of the whole array *x is the first element of the array, every element will have the same size.


[Font] [Default] [Show] [Resize] [History] [Profile]

Out of Bounds

C++ will not check array bounds. If you try to read past the end of an array you will get junk.


[Font] [Default] [Show] [Resize] [History] [Profile]