📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 138question

Data Types, Variables and Expressions · Part 15

Chapter 3: 4 · Computer Science

int. Hence, the output of the above program will be: . The following Table . shows you the conversion pattern.

LHO RHO char short int long float double long double char int int int long float double long double short int int int long float double long double int int int int long float double long double long long long long long float double long double float float float float float float double long double double double double double double double double long double long double long double long double long double long double long double long double long double (RHO – Right Hand Operand; LHO – Left Hand Operand) Chapter Page - - Table . : Implicit conversion of mixed operands ( ) Explicit type conversion C++ allows explicit conversion of variables or expressions from one data type to another specific data type by the programmer. It is called as “type casting”. Syntax: (type-name) expression; Where type-name is a valid C++ data type to which the conversion is to be performed.

Example: #include <iostream> using namespace std; int main( ) float varf= . ; cout << (int) varf; In the above program, variable varf is declared as a float with an initial value . . The value of varf is explicitly converted to an int type in cout statement.

Thus, the final output will be . During explicit conversion, if you assign a value to a type with a greater range, it does not cause any problem. But, assigning a value of a larger type to a smaller type may result in loosing or loss of precision values. S.No Explicit Conversion Problem double to float Loss of precision.

If the original value is out of range for the target type, the result becomes undefined float to int Loss of fractional part. If original value may be out of range for target type, the result becomes undefined long to short Loss of data Table . – Explicit Conversion Problems #include <iostream> using namespace std; int main() double varf= .25255685; cout << (float) varf << endl; cout << (int) varf <<

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →