Header Ads Widget

Type conversion in C

 Type conversion :- 

                            Type conversion is a process of converting data of one type into another type there are two type of the type conversion in C-programming.

1) Implicit type conversion (Automatic type conversion):-

It is automatically done by the system internally without programmer intervention. Usually in a mixed operand expression all the lower data type are converted to the higher data type in the expression.

example:-

#include<stdio.h>
int main()
{
int x=10;
float y=5.5;
double z;
z=(x*5+y*2.3);
printf("Value of Z is %lf",z);
return 0;
}

In this example all the values are converted into double automatically by the system.

2) Explicit Type conversion:-

It is specifically written by the programmer in his code.

Example:-

#include<stdio.h>
int main()
{
int x;
float y;
x=10/3;
y=(float)10/3; // Type conversion
printf("x=%d \n",x);
printf("y=%f",y);
return 0;
}


 
<<Pre - Operators in C                                Next - Decision making construct (if and else)>>


Recommended Post:

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

Key points:-

 MCQs:-