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.
1. What will be the output of the following C code?
#include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c;
}
void main()
{
int *function_pointer;
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}
a) The product of three numbers is:24
b) Compile time error
c) Nothing
d) Varies
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int sub(int a, int b, int c)
{
return a - b - c;
}
void main()
{
int (*function_pointer)(int, int, int);
function_pointer = ⊂
printf("The difference of three numbers is:%d",
(*function_pointer)(2, 3, 4));
}
a) The difference of three numbers is:1
b) Run time error
c) The difference of three numbers is:-5
d) Varies
View Answer
Explanation: None.
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
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
void f(int);
void (*foo)() = f;
int main(int argc, char *argv[])
{
foo(10);
return 0;
}
void f(int i)
{
printf("%d\n", i);
}
a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
void f(int);
void (*foo)(void) = f;
int main(int argc, char *argv[])
{
foo(10);
return 0;
}
void f(int i)
{
printf("%d\n", i);
}
a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
void f(int);
void (*foo)(float) = f;
int main()
{
foo(10);
}
void f(int i)
{
printf("%d\n", i);
}
a) Compile time error
b) 10
c) 10.000000
d) Undefined behaviour
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
void f(int (*x)(int));
int myfoo(int i);
int (*foo)(int) = myfoo;
int main()
{
f(foo(10));
}
void f(int (*i)(int))
{
i(11);
}
int myfoo(int i)
{
printf("%d\n", i);
return i;
}
a) Compile time error
b) Undefined behaviour
c) 10 11
d) 10 Segmentation fault
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
void f(int (*x)(int));
int myfoo(int);
int (*foo)() = myfoo;
int main()
{
f(foo);
}
void f(int(*i)(int ))
{
i(11);
}
int myfoo(int i)
{
printf("%d\n", i);
return i;
}
a) 10 11
b) 11
c) 10
d) Undefined behaviour
View Answer
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.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Practice BCA MCQs
- Check Computer Science Books
- Practice Computer Science MCQs
- Check C Books
- Watch Advanced C Programming Videos