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
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- const_cast in C++ | Type Casting operators
- static_cast in C++ | Type Casting operators
- What are the operators that can be and cannot be overloaded in C++?
- Increment (Decrement) operators require L-value Expression
- Order of operands for logical operators
- Advanced C++ | Conversion Operators
- Bitwise Operators in C/C++
- How to sum two integers without using arithmetic operators in C/C++?
- Execution of printf with ++ operators
- Conditionally assign a value without using conditional and arithmetic operators
- new and delete operators in C++ for dynamic memory
- Overloading stream insertion (<>) operators in C++
- Operators in C / C++
- Written version of Logical operators in C++
- Comparing String objects using Relational Operators in C++
- Relational Operators on STL Array in C++
- unordered_set operators in C++ STL
- Difference between Increment and Decrement Operators
- Left Shift and Right Shift Operators in C/C++
- Unary operators in C/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 firstname.lastname@example.org. 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.