Search code examples
cfunction-declaration

Is [ ] also a declarator (when used in parameter declaration) in C?


6.7.6 Declarators says

Each declarator declares one identifier, and asserts that when an operand of the same form as the declarator appears in an expression, it designates a function or object with the scope, storage duration, and type indicated by the declaration specifiers.

And also states about syntax of parameter:

parameter-declaration:
    declaration-specifiers declarator
    declaration-specifiers abstract-declarator(opt)

For the given function prototype

int f( int a[], int n); 

int a[] declares a parameter with declarator a[] which declares an identifier a.


While in case of

int f( int [], int n);

int [] declares parameter is an array of int with no identifier.
Is [] also a declarator ? ( I think no because it doesn't declare an identifier but syntax for parameter says it is!)


Solution

  • In the identifier-less parameter declaration, you have an abstract declarator. That is, the [] in int f(int [], int n) is an abstract declarator for the array. You can find more in sections §6.7.6 Declarators and §6.7.7 Type names in ISO/IEC 9899:2011 (the C11 standard).