Introduction to Declarations
suggest changeA declaration introduces one or more identifiers and describes their types. A simple object declaration consists of declaration specifiers, one or more declarators, and a terminating semicolon:
int count;
int first, second;
Here, int is a type specifier. The declarators count, first, and second introduce objects of type int.
Declarators can add pointer, array, and function type constructors:
int *pointer; /* pointer to int */
int values[10]; /* array of 10 int */
int compare(int, int); /* function returning int */
int (*callback)(int, int); /* pointer to such a function */
Parentheses affect how a declarator is grouped. In int *compare(int, int), compare would instead be a function returning a pointer to int.
Initialization
An initializer supplies an object's initial value:
int count = 90;
int coordinates[2] = {10, 20};
Initialization is not generally the same operation as assignment. Arrays, for example, can be initialized with an initializer list but cannot later be assigned as complete objects. Qualifiers and storage duration can also make the distinction important.
A declaration may contain multiple declarators:
int value = 1, *pointer = &value;
This is valid, but separate declarations are often clearer when the declarators have different shapes:
int value = 1;
int *pointer = &value;
Function Declarations
int calculate(double input);
This declares a function named calculate that accepts one double argument and returns int. In a declaration, f(void) explicitly means that f takes no parameters. The older form f() does not provide a parameter-type list in C17 and earlier and should be avoided in new code; C23 treats an empty parameter list as specifying no parameters.
Declarations can be difficult to read when several constructors are nested. Start at the identifier and work outward, or introduce a typedef for a meaningful component. See Interpreting Declarations for a systematic method.