-
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;
}
-
- Function A
Function A - Function A
3
Function A - Function A
3
4
Function A - 3
4
Function A
Function A - Function A
Function A
3
4
- Function A
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.