| Type: |
|
| Level: |
Intermediate
|
| Date: |
2006-Dec-08
|
| Visited: |
1279 times
|
| Rating: |

|
| Author: |
Alex Plumpton |
|
|
C++ does some automatic type conversions when the data types are built-in. In the piece of code, a variable r of type integer is declared. pi is of float data type and has the value 3.14189. The value of pi assigned to r.Tthe variable pi will be automatically converted to integer type and thus its value will be truncated.
int r;
float pi=3.14189;
r=pi;
|
Consider the statement that adds two objects as shown. Here, both the left hand side and right hand side of the assignment operator have user-defined data types ie., objects. The operation is carried out smoothly. On the other hand, if we have incompatible operands, say for example, the left hand side has built-in type and the right hand side has user-defined type, then we have to take care of the conversions that are to be done. We shall see the possible type conversions between incompatible data types.
a1=a2+a3