← All topics
Quiz: Type Casting in C++: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. What does this print? (code)
- Q2. Which cast should you use to convert an int to a double?
- Q3. What does dynamiccast<Manager (p) return if p points to an Engineer object (not a Manager)?
- Q4. Why does dynamiccast need the base class to have at least one virtual function?
- Q5. What does this print? (code)
- Q6. What is the legitimate use of constcast?
- Q7. Why are C-style casts like (int)x discouraged in C++?
- Q8. What does an upcast mean?
- Q9. What does the explicit keyword on a single-argument constructor do?
- Q10. Why does the byte-printing reinterpretcast example print different results on different machines?