C Programming Questions and Answers – Pointers to Functions – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Pointers to Functions – 1”.

Pre-requisite for C Pointers to Functions MCQ set: Video Tutorial on C Pointers.

advertisement

1. Which function is not called in the following C program?

  1.     #include <stdio.h>
  2.     void first()
  3.     {
  4.         printf("first");
  5.     }
  6.     void second()
  7.     {
  8.         first();
  9.     }
  10.     void third()
  11.     {
  12.         second();
  13.     }
  14.     void main()
  15.     {
  16.         void (*ptr)();
  17.         ptr = third;
  18.         ptr();
  19.     }

a) Function first
b) Function second
c) Function third
d) None of the mentioned
View Answer

Answer: d
Explanation: None.
Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement

2. How to call a function without using the function name to send parameters?
a) typedefs
b) Function pointer
c) Both typedefs and Function pointer
d) None of the mentioned
View Answer

Answer: b
Explanation: None.
Take C Programming Mock Tests - Chapterwise!
Start the Test Now: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
advertisement

3. Which of the following is a correct syntax to pass a Function Pointer as an argument?
a) void pass(int (*fptr)(int, float, char)){}
b) void pass(*fptr(int, float, char)){}
c) void pass(int (*fptr)){}
d) void pass(*fptr){}
View Answer

Answer: a
Explanation: None.

4. Which of the following is not possible in C?
a) Array of function pointer
b) Returning a function pointer
c) Comparison of function pointer
d) None of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void first()
  3.     {
  4.         printf("Hello World");
  5.     }
  6.     void main()
  7.     {
  8.         void *ptr() = first;
  9.         ptr++
  10.         ptr();
  11.     }

a) Illegal application of ++ to void data type
b) pointer function initialized like a variable
c) Illegal application of ++ to void data type & pointer function initialized like a variable
d) None of the mentioned
View Answer

Answer: c
Explanation: None.
advertisement

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int mul(int a, int b, int c)
  3.     {
  4.         return a * b * c;
  5.     }
  6.     void main()
  7.     {
  8.         int (*function_pointer)(int, int, int);
  9.         function_pointer  =  mul;
  10.         printf("The product of three numbers is:%d",
  11.         function_pointer(2, 3, 4));
  12.     }

a) The product of three numbers is:24
b) Run time error
c) Nothing
d) Varies
View Answer

Answer: a
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int mul(int a, int b, int c)
  3.     {
  4.         return a * b * c;
  5.     }
  6.     void main()
  7.     {
  8.         int (function_pointer)(int, int, int);
  9.         function_pointer = mul;
  10.         printf("The product of three numbers is:%d",
  11.         function_pointer(2, 3, 4));
  12.     }

a) The product of three numbers is:24
b) Compile time error
c) Nothing
d) Varies
View Answer

Answer: b
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void f(int (*x)(int));
  3.     int myfoo(int);
  4.     int (*fooptr)(int);
  5.     int ((*foo(int)))(int);
  6.     int main()
  7.     {
  8.         fooptr = foo(0);
  9.         fooptr(10);
  10.     }
  11.     int ((*foo(int i)))(int)
  12.     {
  13.         return myfoo;
  14.     }
  15.     int myfoo(int i)
  16.     {
  17.         printf("%d\n", i + 1);
  18.     }

a) 10
b) 11
c) Compile time error
d) Undefined behaviour
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.