HP C/iX Reference Manual (31506-90011)
42 Chapter3
Data Types and Declarations
Declarators
Declarator operators have the same precedence and associativity as operators appearing
in expressions. Function declarators and array declarators bind more tightly than pointer
declarators. You can change the binding of declarator operators using parentheses. For
example,
int *x[10];
is an array of 10 pointers to ints. This is because the array declarator binds more tightly
than the pointer declarator. The declaration
int (*x)[10];
is a single pointer to an array of 10 ints. The binding order is altered with the use of
parentheses.
Pointer 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 declares D to be a pointer to type T. D can be any
general declarator of arbitrary complexity. For example, if D were declared as a pointer
already, the use of a second asterisk indicates that D is a pointer to a pointer to T.
Some examples:
int *pi; /* pi: Pointer to an int */
int **ppi; /* ppi: Pointer to a pointer to an int */
int *ap[10]; /* ap: Array of 10 pointers to ints */
int (*pa)[10]; /* pa: Pointer to array of 10 ints */
int *fp(); /* fp: Function returning pointer to int */
int (*pf)(); /* pf: Pointer to function returning an int */
The binding of * (pointer) declarators is of lower precedence than either [ ] (array) or ()
(function) declarators. For this reason, parentheses are required in the declarations of pa
and pf.
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
TD[
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: