Pointers to functions — C++ MCQs

19
Score: 0
Attempted: 0/19
1. What is a pointer to a function?



2. How do you declare a pointer to a function returning int and taking int parameters?



3. If int add(int a,int b){ return a+b; }, how do you assign a pointer to it?



4. Which of the following calls the function using pointer?



5. Function pointer can be passed as an argument to another function?



6. What is output?
int square(int x){ return x*x; }
int main(){ int (*p)(int) = square; cout << (*p)(4); }




7. Which of the following is valid declaration of pointer to function returning void and taking no arguments?



8. Function pointers are useful for



9. Can a pointer to a function point to NULL?



10. Which of the following is correct for array of function pointers?



11. What is the output?
int f(int x){ return x+1; }
int main(){ int (*p)(int)=f; cout << p(9); }




12. How do you pass function pointer to another function?



13. Which of the following is valid to assign function pointer without & operator?



14. Which of the following is valid to call function using pointer?



15. Can function pointer point to member function of class?



16. Which of the following is correct typedef for function pointer returning int and taking two int parameters?



17. What is output?
int add(int a,int b){ return a+b; }
int main(){ int (*fp)(int,int)=add; cout << (*fp)(2,3); }




18. Which is true about function pointers?



19. Function pointers are mainly used for



Contents Copyrights Reserved By T4Tutorials