+ 2
How is a data type converted to another in c++?
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.
0
we can type cast from one data type to another data type
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);