C Programming Questions and Answers – Pointers to Functions – 2

«
»

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

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

advertisement

1. 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;
  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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     int sub(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 = &sub;
  10.         printf("The difference of three numbers is:%d",
  11.         (*function_pointer)(2, 3, 4));
  12.     }

a) The difference of three numbers is:1
b) Run time error
c) The difference of three numbers is:-5
d) Varies
View Answer

Answer: c
Explanation: None.
advertisement

3. One of the uses for function pointers in C is __________
a) Nothing
b) There are no function pointers in c
c) To invoke a function
d) To call a function defined at run-time
View Answer

Answer: d
Explanation: None.

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

advertisement
  1.     #include <stdio.h>
  2.     void f(int);
  3.     void (*foo)() = f;
  4.     int main(int argc, char *argv[])
  5.     {
  6.         foo(10);
  7.         return 0;
  8.     }
  9.     void f(int i)
  10.     {
  11.         printf("%d\n", i);
  12.     }

a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void f(int);
  3.     void (*foo)(void) = f;
  4.     int main(int argc, char *argv[])
  5.     {
  6.         foo(10);
  7.         return 0;
  8.     }
  9.     void f(int i)
  10.     {
  11.         printf("%d\n", i);
  12.     }

a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void f(int);
  3.     void (*foo)(float) = f;
  4.     int main()
  5.     {
  6.         foo(10);
  7.     }
  8.     void f(int i)
  9.     {
  10.         printf("%d\n", i);
  11.     }

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

Answer: d
Explanation: None.

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

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

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

Answer: d
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 (*foo)() = myfoo;
  5.     int main()
  6.     {
  7.         f(foo);
  8.     }
  9.     void f(int(*i)(int ))
  10.     {
  11.         i(11);
  12.     }
  13.     int myfoo(int i)
  14.     {
  15.         printf("%d\n", i);
  16.         return i;
  17.     }

a) 10 11
b) 11
c) 10
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.