C++ | Virtual Functions | Question 12
Predict the output of following C++ program. Assume that there is no alignment and a typical implementation of virtual functions is done by the compiler.
(A), b =
(a == b) cout <<
"a == b"
(a > b) cout <<
"a > b"
"a < b"
(A) a > b
(B) a == b
(C) a < b
(D) Compiler Error
Explanation: Class A has a VPTR which is not there in class B.
In a typical implementation of virtual functions, compiler places a VPTR with every object. Compiler secretly adds some code in every constructor to this.
Quiz of this Question
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!