Array Declarations Syntax
The syntax of a C array declaration is:
array_name[dimension] {[dimension]}
In the context of a simple variable declaration, the syntax is:
type_specification array_variable_name[dimension] {[dimension]};
In the context of a type declaration, the syntax is:
typedef type_specification array_type_name[dimension]
{[dimension]};
Syntax Notes:
• The preprocessor does not evaluate the dimension specified in the brackets. Consequently, the preprocessor accepts any dimensions, including illegal dimensions such as non-numeric expressions, which later cause C compiler errors.
For example, the preprocessor accepts both of the following declarations, even though only the second is legal C:
## typedef int SQUARE["bad expression"];
/* Non-constant expression */
## int cube_5[5][5][5];
• You can specify any number of dimensions. The preprocessor notes the number of dimensions when the variable or type is declared. When the variable is later referenced, it must have the correct number of indices.
• An array variable can be initialized, but the preprocessor does not verify that the initial value is an array aggregate.
• An array of characters is considered to be the pseudo character string type.
The following example illustrates the use of array declarations:
## define COLS 5
## typedef short SQUARE[COLS][COLS];
## SQUARE sq;
## static int matrix[3][3] =
## { {11, 12, 13},
## {21, 22, 23},
## {31, 32, 33} };
## char buf[50];