Networking, Programming and Graphics Tutorials

Type conversions - C++ [1/1]

Type:
Type conversions - C++
Level: Intermediate Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials 
Type conversions - C++
Date: 2006-Dec-08
Type conversions - C++
Visited: 1279 times
Type conversions - C++
Rating: Type conversions - C++
Type conversions - C++
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

Rate this tutorial:                    
Networking, Programming and Graphics Tutorials - Type conversions - C++ [1/1] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: type conversions basic to class type  type conversions in c++  Type conversions + c++  conversion of basic type to class type  conversion from basic type to class type in C++  Type casting from basic to class type in c++  type conversion C++ basic to class type  type conversion in c++,basic to class type  type conversion in from Basic to class type C++  TYPE CONVERSION:BASIC TO CLASS TYPE