1. What is the output of this 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
Answer
Answer: b [Reason:] None.
2. What is the output of this 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
Answer
Answer: c [Reason:] 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.
Answer
Answer: d [Reason:] None.
4. What is the output of this 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("%dn", i);
-
}
a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
Answer
Answer: b [Reason:] None.
5. What is the output of this 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("%dn", i);
-
}
a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned
Answer
Answer: a [Reason:] None.
6. What is the output of this C code?
-
#include <stdio.h>
-
void f(int);
-
void (*foo)(float) = f;
-
int main()
-
{
-
foo(10);
-
}
-
void f(int i)
-
{
-
printf("%dn", i);
-
}
a) Compile time error
b) 10
c) 10.000000
d) Undefined behaviour
Answer
Answer: d [Reason:] None.
7. What is the output of this 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("%dn", i);
-
return i;
-
}
a) Compile time error
b) Undefined behaviour
c) 10 11
d) 10 Segmentation fault
Answer
Answer: d [Reason:] None.
8. What is the output of this 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("%dn", i);
-
return i;
-
}
a) 10 11
b) 11
c) 10
d) Undefined behaviour
Answer
Answer: b [Reason:] None.