What is reinterpret_cast used for?

Options
- converts integer pointer type to any other integer pointer type
- converts any pointer type to any other pointer type
- converts any pointer type to only integer pointer type
- Both a and b


CORRECT ANSWER : Both a and b

Discussion Board
C++ - reinterpret_cast

reinterpret_cast is used for casts that are not type-safe. It converts between types by reinterpreting the underlying bit pattern. It allows any pointer to be converted into any other pointer type. Also allows any integral type to be converted into any pointer type and vice versa.

Prajakta Pandit 01-25-2017 01:17 AM

reinterpret_cast

Option B is Correct Because..
reinterpret_cast Allows any pointer to be converted into any other pointer type. Also allows any integral type to be converted into any pointer type and vice versa.
To do type conversion between incompatible types we should reinterpret_cast operator

Mayur Gaikwad 07-3-2016 04:21 AM

reinterpret_cast

Answer given is wrong: 'a' is not a valid option; 'b' is the only correct answer.

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.

It can also cast pointers to or from integer types. The format in which this integer value represents a pointer is platform-specific. The only guarantee is that a pointer cast to an integer type large enough to fully contain it (such as intptr_t), is guaranteed to be able to be cast back to a valid pointer.


gds 06-12-2014 05:33 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement