ILE C/C++ Language Reference


Arrays

An array is a collection of objects of the same data type. Individual objects in an array, called elements, are accessed by their position in the array. The subscripting operator ([]) provides the mechanics for creating an index to array elements. This form of access is called indexing or subscripting. An array facilitates the coding of repetitive tasks by allowing the statements executed on each element to be put into a loop that iterates through each element in the array.

The C and C++ languages provide limited built-in support for an array type: reading and writing individual elements. Assignment of one array to another, the comparison of two arrays for equality, returning self-knowledge of size are operations unsupported by either language.

An array type describes contiguously allocated memory for a set of objects of a particular type. The array type is derived from the type of its elements, in what is called array type derivation. If array objects are of incomplete type, the array type is also considered incomplete.

Array elements may not be of type void or of function type. However, arrays of pointers to functions are allowed. In C++, array elements may not be of reference type or of an abstract class type.

C Two array types that are similarly qualified are compatible if the types of their elements are compatible. For example,

char ex1[25];
const char ex2[25];

are not compatible. The composite type of two compatible array types is an array with the composite element type. The sizes of both original types must be equivalent if they are known.

Except in certain contexts, an unsubscripted array name (for example, region instead of region[4]) represents a pointer whose value is the address of the first element of the array, provided that the array has previously been declared. The exceptions are when the array name passes the array itself. For example, the array name passes the entire array when it is the operand of the sizeof operator or the address (&) operator.

Similarly, an array type in the parameter list of a function is converted to the corresponding pointer type. Information about the size of the argument array is lost when the array is accessed from within the function body.

Related References


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]