Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – Pointers to Functions

C Programming Questions and Answers – Pointers to Functions

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

 

#include <stdio.h>

void first()

{

printf(“first”);

}

void second()

{

first();

}

void third()

{

second();

}

void main()

{

void (*ptr)();

ptr = third;

ptr();

}

a) Function first

b) Function second

c) Function third

d) None of the mentioned

View Answer

 

Answer:d

2.How to call a function without using the function name to send parameters?

a) typedefs

b) Function pointer

c) Both (a) and (b)

d) None of the mentioned

View Answer

 

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){}

View Answer

 

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

View Answer

 

Answer:d

5.What is the output of this C code?

 

#include <stdio.h>

void first()

{

printf(“Hello World”);

}

void main()

{

void *ptr() = first;

ptr++

ptr();

}

a) Illegal application of ++ to void data type

b) pointer function initialized like a variable

c) Both (a) and (b)

d) None of the mentioned

View Answer

Answer:c

6.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)(int, int, int);

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) Run time error

c) Nothing

d) Varies

View Answer

Answer:a

7.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)(int, int, int);

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

Answer:b

8.What is the output of this C code?

 

#include <stdio.h>

void f(int (*x)(int));

int myfoo(int);

int (*fooptr)(int);

int ((*foo(int)))(int);

int main()

{

fooptr = foo(0);

fooptr(10);

}

int ((*foo(int i)))(int)

{

return myfoo;

}

int myfoo(int i)

{

printf(“%d\n”, i + 1);

}

a) 10

b) 11

c) Compile time error

d) Undefined behaviour

View Answer

Answer:b

9.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

View Answer

Answer:b 

 

10.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 = &sub;

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

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.

View Answer

Answer:d

 

12.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(“%d\n”, i);

}

a) Compile time error

b) 10

c) Undefined behaviour

d) None of the mentioned

View Answer

Answer:b

 

13.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(“%d\n”, i);

}

a) Compile time error

b) 10

c) Undefined behaviour

d) None of the mentioned

View Answer

Answer:a

 

14.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(“%d\n”, i);

}

a) Compile time error

b) 10

c) 10.000000

d) Undefined behaviour

View Answer

Answer:d

 

15.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(“%d\n”, i);

return i;

}

a) Compile time error

b) Undefined behaviour

c) 10 11

d) 10 Segmentation fault

View Answer

Answer:d

 

16.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(“%d\n”, i);

return i;

}

a) 10 11

b) 11

c) 10

d) Undefined behaviour

View Answer

Answer:b

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button