What happens when dynamic_cast<Derived*>(basePtr) is applied and basePtr does not actually point to a Derived object?
Correct answer B. It returns a null pointer
Explanation
dynamic_cast checks the object's dynamic type at run time and requires a polymorphic base class. For pointer targets, a failed cast returns a null pointer, so code typically writes if (auto d = dynamic_cast(p)). For reference targets there is no null reference, so a failed cast throws std::bad_cast instead.
Answer checked How we write and check questions
Discussion