Tuesday 12 February 2013

Type Casting in C++ Programming Language



It is a process of converting one data type into another. There are two types of data type conversion. They are,

1) Explicit conversion
2) Implicit conversion

1) Explicit conversion

It is a process of converting one data type into another explicitly using cast operator. The general form is

newtype (variable or expression);

(or)

(new type) variable or expression;

2) Implicit conversion or automatic conversion

If an expression contains different type of operands, the lower data type operands are automatically converted to higher data types. This conversion is called implicit conversion. The lower data types are data types which occupies less memory space and higher data types are data types which occupies large memory space.

float x;
x=6 + 8.3;

The operands 6 and 8.5 in the expression are of different data types. But during execution the integer data 5 is automatically converted into float type and the operation is performed. So the result is 14.5.

0 comments:

Post a Comment

Powered by Blogger.