What does the following expression means ? char ∗(∗(∗ a[N]) ( )) ( );

2014

What does the following expression means ?
 char ∗(∗(∗ a[N]) ( )) ( );

  1. A.

    a pointer to a function returning array of n pointers to function returning character pointers.

  2. B.

    a function return array of N pointers to functions returning pointers to characters

  3. C.

    an array of n pointers to function returning pointers to characters

  4. D.

    an array of n pointers to function returning pointers to functions returning pointers to characters. 

Attempted by 249 students.

Show answer & explanation

Correct answer: D

Answer: an array of N pointers to functions returning pointers to functions returning pointers to characters.

How to read the declaration char *(*(* a[N])())():

  • Start at the identifier a: a is an array of N

  • a[N] -> array of N of ...

  • *a[N] -> array of N of pointers to ...

  • (*a[N])() -> array of N of pointers to functions returning ...

  • *(*a[N])() -> array of N of pointers to functions returning pointers to ...

  • (*(*a[N])())() -> array of N of pointers to functions returning pointers to functions returning ...

  • The leading char * means the innermost returned entity is a pointer to char.

So the full meaning is: each element of the array is a pointer to a function that returns a pointer to another function; that inner function returns a char pointer.

Equivalent description with typedefs (shows nesting clearly):

  • typedef char * chptr; // chptr is pointer to char

  • typedef chptr (*pf1)(); // pf1 is pointer to function returning char*

  • typedef pf1 (*pf2)(); // pf2 is pointer to function returning pf1

  • pf2 a[N]; // array of N pf2, i.e. array of N pointers to functions returning pointers to functions returning char*

This confirms the declaration describes an array of N pointers to functions returning pointers to functions returning pointers to characters.

Explore the full course: Mppsc Assistant Professor