Which option gives the correct interpretation of the following declaration in…

2018

Which option gives the correct interpretation of the following declaration in C++?
int(*p[5])();

Answer: B. p is an array of pointers to functionTo parse the declaration int(*p[5])(), start with the identifier p. The brackets [5] indicate that p is an array of 5 elements. The parentheses around *p[5]…

  1. A.

    p is a pointer to function

  2. B.

    p is an array of pointers to function

  3. C.

    p is a pointer to such function which return type is array

  4. D.

    p is a pointer to an array of functions

Attempted by 268 students.

Show answer & explanation

Correct answer: B

To parse the declaration int(*p[5])(), start with the identifier p. The brackets [5] indicate that p is an array of 5 elements. The parentheses around *p[5] override the default precedence, meaning each element of the array is a pointer. Finally, the trailing () indicates that these pointers point to functions returning an integer. Thus, p is an array of 5 pointers to functions that return int.

Explore the full course: Dsssb Tgt Computer Science Paper 2

Loading lesson…