+ 2

How is a data type converted to another in c++?

7th Jan 2017, 2:07 PM
Max Otuteye
Max Otuteye - avatar
3 Respostas
+ 5
Suppose you have declared a integer variable as int i =4.0 and Just display it by using cout <<i; it will show you only 4 because the variable is of integer type and compiler will convert it to integer before performing any operation on it. Hope this helps.
7th Jan 2017, 6:33 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
we can type cast from one data type to another data type
7th Jan 2017, 4:06 PM
Sai Krish
Sai Krish - avatar
0
Using type casting because typecasting enables data type conversion. C++ supports Implicit conversions and Explicit conversion. Implicit conversions automatically performed when a value is copied to a compatible type. If there is an operation between an int and a float, the int is promoted to float before performing operation. You can cast types explicitly as follows : int i, j, k;  k = i * long(j);
14th Jan 2017, 7:23 AM
akshay shinde
akshay shinde - avatar