Which declaration creates a pointer to a function taking two ints and returning an int?
Correct answer
C. int (*fp)(int, int);
20 views
C. int (*fp)(int, int);
20 views
The parentheses around (*fp) bind the star to the name before the call parentheses apply, so fp is a pointer to a function, not a function returning a pointer. Without them, int *fp(int, int) declares a function returning int*. Function pointers enable callbacks such as qsort's comparator and are dereferenced implicitly when called, so fp(1, 2) and (*fp)(1, 2) are equivalent.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.