Home / MCQ Bank / Computer
Computer Plus Plus Miscellaneous

What will be the output of the following C++ code? #include <iostream> using namespace std; struct A { virtual void f() { cout << "Class A" << endl; } }; struct B : A { virtual void f() { cout << "Class B" << endl; } }; struct C : A { virtual void f() { cout << "Class C" << endl; } }; void f(A* arg) { B* bp = dynamic_cast<B*>(arg); C* cp = dynamic_cast<C*>(arg); if (bp) bp -> f(); else if (cp) cp -> f(); else arg -> f(); }; int main() { A aobj; C cobj; A* ap = &cobj; A* ap2 = &aobj; f(ap); f(ap2); }

Select the best option to verify your answer:
Show Correct Answer
Correct Answer: Option C • Both Class C & A

Related Computer Questions

Which class is used for reading character streams in a platform-independent way in Java? What is the range of octal notation (\nnn)? Which of the following is a type of systems software used on microcomputers? What does the term "thread synchronization" mean in multithreading? Rendering engine is not responsible for