Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Testpm 
{
    public:
    void m_func1() 
    { 
        cout << "func1\n";
    }
    int m_num;
};
void (Testpm :: *pmfn)() = &Testpm :: m_func1;
int Testpm :: *pmd = &Testpm :: m_num;
int main() 
{
    Testpm ATestpm;
    Testpm *pTestpm = new Testpm;
    (ATestpm.*pmfn)();
    (pTestpm ->* pmfn)();
    ATestpm.*pmd = 1;
    pTestpm ->* pmd = 2;
    cout << ATestpm.*pmd << endl
    << pTestpm ->* pmd << endl;
}

A. func1

B. func1
func1

C. 1
2

D. func1
func1
1
2

Answer: Option D


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it