Implicit type Conversion in C | Automatic type conversion in C
Implicit conversion means automatic conversion. It is the way in which the output of an arithmetic expression is converted automatically into a particular data type.
The basic rule of implicit conversion is that the output of an expression will be of that data type which has the highest number of bytes and range.
For example if one operand is of int type and other of float type, the output will be of float type as float type has larger size and range of values compared to int data type.
There are some rules of implicit conversion which are as follows:
|Data type of first operand||Data type of second operand||Data type of Output|
|short||long double||long double|
|int||long double||long double|
|long||long double||long double|
|float||long double||long double|
|double||long double||long double|
|long double||long double||long double|
|long double||char||long double|
|Program to demonstrate implicit conversion.|
float d, e;
c=a/b; /*Line 10*/
d=a/b; /*Line 12*/
e=a/d; /*Line 14*/
c=a/d; /*Line 16*/
** In line 10 of above program, a and b are of int type so result of a/b will be of int type i.e. 3 which has been assigned to variable c which is also of int type.
So c will contain 3.
In line 12, a and b are of int type so result of a/b will be of int type i.e. 3. which has been assigned to variable d which is also of float type.
So d will contain 3.000000.
In line 14, a is of int type and d is of float type so result of a/b will be of float type i.e. 3.333333 which has been assigned to variable e which is also of float type.
So e will contain 3.333333.
In line 16, a is of int type and d is of float type so result of a/b will be of float type i.e. 3.333333 which has been assigned to variable c which is of int type.
So c will contain 3 as int variable c can’t contain digits after decimal point.