Complex Declarations

If a declarator contains only one identifier, with or without an initialization, the declaration is called a simple declaration. In a complex declaration, the declarator also contains additional type information. This is necessary in declarations of pointers, arrays, and functions. Such declarations use the three operators, shown in Table 1-17.

Table 1-17. Operators for complex declarations

Operator

Meaning

*

Pointer to

[ ]

Array of element type

( )

Function returning value of type

The operators in Table 1-17 have the same precedence in declarations as in expressions. Parentheses can also be used to group operands.

Complex declarators are always interpreted beginning with the identifier being declared. Then the following steps are repeated until all operators are resolved:

  1. Any pair of parentheses () or square brackets [] appearing to the right is interpreted.

  2. If there are none, then any asterisk appearing to the left is interpreted.

For example:

char *strptr[100];

This declaration identifies strptr as an array. The array’s 100 elements are pointers to char.

Get C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.