The following ‘C’ statement : int * f[ ]( ) ; declares :

2016

The following ‘C’ statement :

int * f[ ]( ) ;

declares :

  1. A.

    A function returning a pointer to an array of integers.

  2. B.

    Array of functions returning pointers to integers.

  3. C.

    A function returning an array of pointers to integers.

  4. D.

    An illegal statement.

Attempted by 245 students.

Show answer & explanation

Correct answer: D

Parsing the declaration:

Start with the identifier f. The postfix [] immediately after the name makes f an array of unspecified size.

The following () applies to each array element, so each element would have to be a function.

The leading * is not missed; it makes the function return a pointer to int. In other words, the parsed meaning is: array of functions returning int *.

However, this parsed meaning is not valid in standard C because an array cannot have function type as its element type. That is why the best answer is Option D: an illegal statement.

If the intention were an array of pointers to functions returning int *, the parentheses would have to bind the * with f:

int *(*f[])();

So the given declaration int * f[](); is illegal, while int *(*f[])(); is the valid array-of-function-pointers form.

Explore the full course: Mppsc Assistant Professor