Reinterpret_Cast operator - Type casting
How is reinterpret_cast operator used in C++?
Explanation
Reinterpret_cast operator is used convert a pointer of one type to another type even that of an unrelated class. This is type casting in C++.
Example :
#include <iostream.h> int main() { int *ptr = new int(20); cout << "First value = " << *ptr << endl; void *ptr2 = reinterpret_cast(ptr); int *ptr3 = reinterpret_cast(ptr2); cout << "Final reinterpret cast value is::" << *ptr3 << endl; } |
Result of Type Casting:
First value = 20
Final reinterpret cast value is:: 20
In the above example, the reinterpret_cast operator is used convert a integer pointer to a pointer of type "void" then converted into a integer pointer.