What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class X
{
public:
int a;
void f(int b)
{
cout<< b << endl;
}
};
int main()
{
int X :: *ptiptr = &X :: a;
void (X :: * ptfptr) (int) = &X :: f;
X xobject;
xobject.*ptiptr = 10;
cout << xobject.*ptiptr << endl;
(xobject.*ptfptr) (20);
}
#include <iostream>
using namespace std;
class X
{
public:
int a;
void f(int b)
{
cout<< b << endl;
}
};
int main()
{
int X :: *ptiptr = &X :: a;
void (X :: * ptfptr) (int) = &X :: f;
X xobject;
xobject.*ptiptr = 10;
cout << xobject.*ptiptr << endl;
(xobject.*ptfptr) (20);
}A. 10
20
B. 20
10
C. 20
D. 10
Answer: Option A

Join The Discussion