HP C A.06.05 Reference Manual

Data Types and Declarations
Declarators
Chapter 356
Array Declarators
If D is a declarator, and T is some combination of type specifiers and storage class specifiers
(such as int), then the declaration
T D[
constant-expression
];
declares D to be an array of type T.
You declare multidimensional arrays by specifying additional array declarators. For example,
a 3 by 5 array of integers is declared as follows:
int x[3][5];
This notation (correctly) suggests that multidimensional arrays in C are actually arrays of
arrays. Note that the [ ] operator groups from left to right. The declarator x[3][5] is
actually the same as ((x[3])[5]). This indicates that x is an array of three elements each of
which is an array of five elements. This is known as row-major array storage.
You can omit the constant-expression giving the size of an array under certain circumstances.
You can omit the first dimension of an array (the dimension that binds most tightly with the
identifier) in the following cases:
If the array is a formal parameter in a function definition.
If the array declaration contains an initializer.
If the array declaration has external linkage and the definition (in another translation
unit) that actually allocates storage provides the dimension.
Note that the long long data type cannot be used to declare an array's size.
Following are examples of array declarations:
int x[10]; /* x: Array of 10 integers */
float y[10][20]; /* y: Matrix of 10x20 floats */
extern int z[ ]; /* z: External integer array of undefined dimension */
int a[ ]={2,7,5,9}; /* a: Array of 4 integers */
int m[ ][3]= { /* m: Matrix of 2x3 integers */
{1,2,7},
{6,6,6} };
Note that an array of type T that is the formal parameter in a function definition has been
converted to a pointer to type T. The array name in this case is a modifiable lvalue and can
appear as the left operand of an assignment operator. The following function will clear an
array of integers to all zeros. Note that the array name, which is a parameter, must be a
modifiable lvalue to be the operand of the ++ operator.