Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

What is meaning of following declaration?
 int(*ptr[5])();


  1.    ptr is pointer to function.
  2.    ptr is array of pointer to function.
  3.    ptr is pointer to such function which return type is array.
  4.    ptr is pointer to array of function.
 Discuss Question
Answer: Option B. -> ptr is array of pointer to function.

In this expression, ptr is array not pointer.


Question 2.

which of the following can be passed in function pointers?


  1.    variables
  2.    data types
  3.    functions
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> functions

None.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int func (int a, int b)
4.
{
5.
cout
  1.    2323
  2.    232
  3.    23
  4.    compile time error
 Discuss Question
Answer: Option D. -> compile time error

In this program, we can’t do the casting from char to int, So it is raising an error.


Question 4.

What are the mandatory part to present in function pointers?


  1.    &
  2.    retrun values
  3.    data types
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> data types

The data types are mandatory for declaring the variables in the function pointers.


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int n(char, int);
4.
int (*p) (char, int) = n;
5.
int main()
6.
{
7.
(*p)('d', 9);
8.
p(10, 9);
9.
return 0;
10.
}
11.
int n(char c, int i)
12.
{
13.
cout
  1.    d9 9
  2.    d9d9
  3.    d9
  4.    compile time error
 Discuss Question
Answer: Option A. -> d9 9

None.
Output:
$ g++ pfu1.cpp
$ a.out
d9
9


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void func(int x)
4.
{
5.
cout
  1.    2
  2.    20
  3.    21
  4.    22
 Discuss Question
Answer: Option D. -> 22

As we are calling the function two times with the same value, So it is printing as 22.
Output:
$ g++ pfu.cpp
$ a.out
22


Question 7.


What is te output of this program?


1.
#include
2.
using namespace std;
3.
int add(int first, int second)
4.
{
5.
return first + second + 15;
6.
}
7.
int operation(int first, int second, int
(*functocall)(int, int))
8.
{
9.
return (*functocall)(first, second);
10.
}
11.
int main()
12.
{
13.
int a;
14.
int (*plus)(int, int) = add;
15.
a = operation(15, 10, plus);
16.
cout
  1.    25
  2.    35
  3.    40
  4.    45
 Discuss Question
Answer: Option C. -> 40

In this program, we are adding two numbers with 15, So we got the output as 40.
Output:
$ g++ pfu2.cpp
$ a.out
40


Question 8.

What we will not do with function pointers?


  1.    allocation of memory
  2.    de-allocation of memory
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> both a & b

As it is used to execute a block of code, So we will not allocate or deallocate memory.


Question 9.

What is the default calling convention for a compiler in c++?


  1.    __cdecl
  2.    __stdcall
  3.    __pascal
  4.    __fastcall
 Discuss Question
Answer: Option A. -> __cdecl

None.


Question 10.

To which does the function pointer point to?


  1.    variable
  2.    constants
  3.    function
  4.    absolute variables
 Discuss Question
Answer: Option C. -> function

None.


Latest Videos

Latest Test Papers