Wednesday, 18 April 2012

Explain the ways in which type conversion can be done. | C++

Type conversion refers to the process of assigning a value of one data type to a variable of another data type. There are two types of conversions- implicit and explicit.
Implicit conversions can be handled by the compiler and the explicit conversions can be handled by a user. Following are the ways by which type conversion can be performed in C++:
1. (const_cast (expression)—Allows you to convert a variable's data type by adding a const or volatile modifier to it
2. dynamic_cast (expression) —Supports runtime identification of class objects
3. reinterpret_cast (expression) —Supports low-level reinterpretation of the bit pattern of an expression
4. static_cast (expression) —Makes explicit conversions of types into non-equivalent types, such as conversion of pointers from base class to derived class or vice-versa

No comments: