reinterpret_cast is a type of casting operator used in C++.
- It is used to convert one pointer of another pointer of any type, no matter either the class is related to each other or not.
- It does not check if the pointer type and data pointed by the pointer is same or not.
data_type *var_name = reinterpret_cast <data_type *>(pointer_variable);
- It doesn’t have any return type. It simply converts the pointer type.
- It takes only one parameter i.e., the source pointer variable (p in above example).
65 A 0x1609c20 A
Purpose for using reinterpret_cast
- reinterpret_cast is a very special and dangerous type of casting operator. And is suggested to use it using proper data type i.e., (pointer data type should be same as original data type).
- It can typecast any pointer to any other data type.
- It is used when we want to work with bits.
- If we use this type of cast then it becomes a non-portable product. So, it is suggested not to use this concept unless required.
- It is only used to typecast any pointer to its original type.
- Boolean value will be converted into integer value i.e., 0 for false and 1 for true.
12 5 10 a 1 1
In class A
Related link :
https://stackoverflow.com/questions/573294/when-to-use-reinterpret-cast” rel=”noopener” target=”_blank
- const_cast in C++ | Type Casting operators
- static_cast in C++ | Type Casting operators
- Operators in C / C++
- unordered_set operators in C++ STL
- Unary operators in C/C++
- Bitwise Operators in C/C++
- What are the operators that can be and cannot be overloaded in C++?
- Type Conversion in C++
- Type of 'this' pointer in C++
- Advanced C++ | Conversion Operators
- Relational Operators on STL Array in C++
- Execution of printf with ++ operators
- How to sum two integers without using arithmetic operators in C/C++?
- Array Type Manipulation in C++
- What is the size_t data type in C?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.