Q3. What is the function of type conversion? Write the standard conversion rules of C++.
Ans. The process of converting one predefined type into another is called Type Conversion.
C++ facilitates the type conversion in two forms:
- Implicit Type Conversion
An implicit type conversion is a conversion performed by the compiler without programmer’s intervention.
- Explicit Type Conversion
The explicit type conversion is user-defined that forces an expression to be specific type.
Standard Conversion Rules in C++
|Step No.||If either’s type is||Then result type of other operand||Otherwise|
|1.||long double||long double||step 2|
|4.||–||Integral promotion takes place followed by step 5.||–|
|5.||unsigned long||unsigned long||step 6|
|6.||long int and the other is unsigned int||
|8.||unsigned||Unsigned||both operands are int.|
Once these conversion rules have been applied, each pair of operands is of the same type and the result of each operation is the same as the type of both operands.