CPP

CPP

Pointer to Function has 10 Questions

To which does the function pointer point to?

variable
constants
function
absolute variables
What we will not do with function pointers?

allocation of memory
de-allocation of memory
both a & b
none of the mentioned
What is the default calling convention for a compiler in c++?

__cdecl
__stdcall
__pascal
__fastcall
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 << a;
  17.         return 0;
  18.     }

25
35
40
45
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     void func(int x)
  4.     {
  5.         cout << x ;
  6.     }
  7.     int main()
  8.     {
  9.         void (*n)(int);
  10.         n = &func;
  11.         (*n)( 2 );
  12.         n( 2 );
  13.         return 0;
  14.     }

2
20
21
22
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 << c <<  i;
  14.         return 0;
  15.     }

d9 ? ? ?9
d9d9
d9
compile time error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int func (int a, int b)
  4.     {
  5.         cout << a;
  6.         cout << b;
  7.         return 0;
  8.     }
  9.     int main(void)
  10.     {
  11.         int(*ptr)(char, int);
  12.         ptr = func;
  13.         func(2, 3);
  14.         ptr(2, 3);
  15.         return 0;
  16.     }

2323
232
23
compile time error
What are the mandatory part to present in function pointers?

&
retrun values
data types
none of the mentioned
which of the following can be passed in function pointers?

variables
data types
functions
none of the mentioned
What is meaning of following declaration? ????int(*ptr[5])();

ptr is pointer to function.
ptr is array of pointer to function.
ptr is pointer to such function which return type is array.
ptr is pointer to array of function.