A declarator designates a data object or function. Declarators appear in most data definitions and declarations and in some type definitions.
In a declarator, you can specify the type of an object to be an array, a pointer, or a reference. You can also perform initialization in a declarator.
A declarator has the form:
declarator >>-+----------------------+--direct_declarator----------------->< | .------------------. | | V | | '---pointer_operator-+-'
direct_declarator >>-+-declarator_name-------------------------------------------------------------------------------------+->< +-direct_declarator--(--parameter_declaration_list--)--+---------------+--+-------------------------+-+ | '-cv_qualifiers-' '-exception_specification-' | +-direct_declarator--[--+---------------------+--]----------------------------------------------------+ | '-constant_expression-' | '-(--declarator--)------------------------------------------------------------------------------------'
pointer_operator >>-+-*--+---------------+--------------------------------+----->< | '-cv_qualifiers-' | +-&---------------------------------------------------+ '-+----+--nested_name_specifier--*--+---------------+-' '-::-' '-cv_qualifiers-'
The syntax for a declarator name in C:
declarator_id >>-+------------+---------------------------------------------->< '-identifier-'
The syntax for a declarator name in C++:
declarator_id >>-+----------------------------------------------+------------>< +-identifier_expression------------------------+ '-+----+--+-----------------------+--type_name-' '-::-' '-nested_name_specifier-'
Notes on the declarator syntax
The following table provides some examples of declarators:
Example | Description |
---|---|
int owner | owner is an int data object. |
int *node | node is a pointer to an int data object. |
int names[126] | names is an array of 126 int elements. |
int *action( ) | action is a function returning a pointer to an int. |
volatile int min | min is an int that has the volatile qualifier. |
int * volatile volume | volume is a volatile pointer to an int. |
volatile int * next | next is a pointer to a volatile int. |
volatile int * sequence[5] | sequence is an array of five pointers to volatile int objects. |
extern const volatile int clock | clock is a constant and volatile integer with static storage duration and external linkage. |
Related References