C Programming Questions and Answers on Pointers to Functions for Freshers

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

  1.     #include 
  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
Answer: d
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
Answer: b
3. 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){}
Answer: a
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
Answer: d
5. What is the output of this C code?
  1.     #include 
  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
Answer: c
6. What is the output of this C code?
  1.     #include 
  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
Answer: a
7. What is the output of this C code?
  1.     #include 
  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
Answer: b
8. What is the output of this C code?
  1.     #include 
  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
Answer: b
9. What is the output of this C code?
  1.     #include 
  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
Answer: b
10. What is the output of this C code?
  1.     #include 
  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 = ⊂
  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
Answer: c
11. 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.
Answer: d
12. What is the output of this C code?
  1.     #include 
  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
Answer: b
13. What is the output of this C code?
  1.     #include 
  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
Answer: a
14. What is the output of this C code?
  1.     #include 
  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
Answer: d
15. What is the output of this C code?
  1.     #include 
  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
Answer: d
16. What is the output of this C code?
  1.     #include 
  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
Answer: b

Related

HTML Multiple Choice Questions & Answers on Web Browsers for Freshers

1. Rendering engine is not responsible for a) parsing the markup content (HTML)b) parsing style information (CSS, XSL, and so on)c) generating a visual presentation of the formatted content includi...

Data Structure Questions and Answers on Reverse of a String using Recursion

1. Consider the following iterative implementation used to reverse a string: #include #include void reverse_string(char *s) { int len = strlen(s); int i,j; i=0; j=len-1...

Java Multiple Choice Questions & Answers on Arrays for Freshers

1. Which of these operators is used to allocate memory to array variable in Java? a) mallocb) allocc) newd) new malloc Answer:c Explanation:Operator new allocates block of memory specified by the...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item