Q:

When should static_cast, dynamic_cast, const_cast, and reinterpret_cast be used?

0

When should static_cast, dynamic_cast, const_cast, and reinterpret_cast be used?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

dynamic_cast:  It is used for converting pointers/references within an inheritance hierarchy.

static_cast: It is used for ordinary type conversions.

reinterpret_cast: reinterpret_cast converts any pointer type to any other pointer type, even of unrelated classes. The operation result is a simple binary copy of the value from one pointer to the other. All pointer conversions are allowed: neither the content pointed nor the pointer type itself is checked..Use with extreme caution.

const_cast: It is used for casting away const/volatile. Avoid this unless you are stuck using a const-incorrect API.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions For Experienced

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How does the compilation/linking process work in c... >>
<< What is typecasting in c++?...