Recall & Review
beginner
What is type casting in C++?
Type casting is the process of converting a variable from one data type to another, like changing an integer to a float.
Click to reveal answer
beginner
What is the difference between implicit and explicit type casting?
Implicit casting happens automatically by the compiler, while explicit casting is done manually by the programmer using cast operators.
Click to reveal answer
intermediate
How do you perform explicit type casting using C++ style casts?
You can use
static_cast<new_type>(expression) to convert types explicitly and safely in C++.Click to reveal answer
advanced
What does
reinterpret_cast do in C++?reinterpret_cast converts one pointer type to another, treating the bits as a different type without changing them. Use carefully as it can be unsafe.Click to reveal answer
intermediate
Why should you avoid C-style casts in modern C++?
C-style casts are less safe because they can perform many conversions without warning. Modern C++ prefers
static_cast, dynamic_cast, const_cast, and reinterpret_cast for clarity and safety.Click to reveal answer
Which cast is safest for converting between related types in C++?
✗ Incorrect
static_cast is safe for converting between related types like int to float or base class pointer to derived class pointer (with care).
What type of cast should you use to remove constness from a variable?
✗ Incorrect
const_cast is used to add or remove const or volatile qualifiers.
What happens during implicit type casting?
✗ Incorrect
Implicit casting is automatic conversion done by the compiler when safe.
Which cast is used to safely convert pointers in an inheritance hierarchy at runtime?
✗ Incorrect
dynamic_cast checks types at runtime and safely converts pointers or references in class hierarchies.
Why is
reinterpret_cast considered unsafe?✗ Incorrect
reinterpret_cast treats the bits as a different type without changing them, which can cause undefined behavior if used incorrectly.
Explain the main types of type casting in C++ and when to use each.
Think about automatic vs manual conversions and safety.
You got /6 concepts.
Describe why modern C++ prefers specific cast operators over C-style casts.
Consider how each cast operator has a clear role.
You got /4 concepts.