Home » C++ Programming » Pointers » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Example
    {
    public:
    void FunctionA()
    {
    cout << "Function A" << endl;
    }
    int num;
    };
    void (Example :: *ptr1)() = &Example :: FunctionA;
    int Example :: *ptr2 = &Example :: num;
    int main()
    {
    Example object;
    Example *ptrObject = new Example;
    (object.*ptr1)();
    (ptrObject ->* ptr1)();
    object.*ptr2 = 3;
    ptrObject ->* ptr2 = 4;
    cout << object.*ptr2 << endl
    << ptrObject ->* ptr2 << endl;
    }
    1. Function A
      Function A
    2. Function A
      3
      Function A
    3. Function A
      3
      4
      Function A
    4. 3
      4
      Function A
      Function A
    5. Function A
      Function A
      3
      4
Correct Option: E

In this program, As we are passing the value twice to the method
in the class, It is printing the Function A twice and then it is printing the given value.



Your comments will be displayed only after manual approval.