Arrays

Arrays

Arrays of data types can be declared using the syntax “<data type> <variable name> [ <constant expression> ]”. <data type> can be any built-in data type or a custom structure, union, enumeration, or typedef. See Data Types, Typedefs, Structs, Unions, and Enums for information on what is valid in a <data type>.

int myArray[32];

The array size must be a constant number and must be larger than 0.

The array size can be a float or double type, but it will be automatically cast to an int, which is in contrast with C, which would throw an error.

The individual elements of the array can be accessed using the “[ ]” operator. For example:

for ( int i = 0; i < 32; i++ ) myArray[i] = i;
Copyright © 2006 Shawn (L. Spiro) Wilcoxen