Pointer to Function Cpp MCQ

Errorlogger
0
1. To which does the function pointer point to?
a) variable
b) constants
c) function
d) absolute variables



2. What we will not do with function pointers?
a) allocation of memory
b) de-allocation of memory
c) both a & b
d) none of the mentioned



3. What is the default calling convention for a compiler in c++?
a) __cdecl
b) __stdcall
c) __pascal
d) __fastcall



4. What is te output of this program?
  1.     #include <iostream>
  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.     }
a) 25
b) 35
c) 40
d) 45



5. What is the output of this program?
  1.     #include <iostream>
  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.     }
a) 2
b) 20
c) 21
d) 22



6. What is the output of this program?
  1.     #include <iostream>
  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.     }
a) d99
b) d9d9
c) d9
d) compile time error



7. What is the output of this program?
  1.     #include <iostream>
  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.     }
a) 2323
b) 232
c) 23
d) compile time error



8. What are the mandatory part to present in function pointers?
a) &
b) retrun values
c) data types
d) none of the mentioned



9. which of the following can be passed in function pointers?
a) variables
b) data types
c) functions
d) none of the mentioned




10. What is meaning of following declaration?
    int(*ptr[5])();
a) ptr is pointer to function.
b) ptr is array of pointer to function.
c) ptr is pointer to such function which return type is array.
d) ptr is pointer to array of function.

Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !