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: 1197 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: c++ "automatic type conversions" operations  basic data type to class type conversion in c++  type conversion of basic to class type in C++  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  type casting and type conversion in c++  see my ip and a type of os  type IP in dos  type of overloading in c++  type casting/c++  RDP port type  type overloading in c++  RDP port type  type of function in c++  type casting-C++  type overloading c++