HP C A.06.05 Reference Manual
Data Types and Declarations
Declarators
Chapter 3 55
Description
Various special symbols may accompany declarators. Parentheses change operator precedence
or specify functions. The asterisk specifies a pointer. Square brackets indicate an array. The
constant-expression specifies the size of an array.
A declarator specifies one identifier and may supply additional type information. When a
construction with the same form as the declarator appears in an expression, it yields an entity
of the indicated scope, storage class, and type.
If an identifier appears by itself as a declarator, it has the type indicated by the type specifiers
heading the declaration.
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.