Type Casting in OOP C++
A type cast is basically a conversion from one type to another. There are two types of type conversion: Implicit Type Conversion Also known as ‘automatic type conversion’. Done by the compiler on its own, without any external trigger from the user. Generally, takes place when in an expression more than one data type is present. In such condition type conversion takes place to avoid lose of data. All the data types of the variables are upgraded to the data type of the variable with largest data type. It is possible for implicit conversions to lose information, signs can be lost , and overflow can occur . Explicit Type Conversion: This process is also called type casting and it is user-defined. Here the user can typecast the result to make it of a particular data type. In C++, it can be done by two ways: Converting by assignment: This is done by explicitly defining the required type in front of the expression in parenthesis. This can be also considered as forceful casting. Syntax: type expression where type indicates the data type to which the final result is converted.
Download
0 formatsNo download links available.