C – Type Casting

Home/Learn C Programming/C – Type Casting
C – Type Casting 2017-08-07T14:23:39+00:00

Type Casting :

  • The process of converting one data type  to another datatype is called as type casting or type conversion.
  • In C language type conversion is an arithmetic expression  will be done automatically. This is called implicit conversion.
  • If we want to store a value of one type into a variable of another type, we must caste the value to be stored by preceding it with the type name in parenthesis.This is called explicit conversion or type casting.

Example :

int a,b;

float c,d;

a=5;

b=2;

c=a/b;      c=2.00   Automatic (or) implicit conversion

d=(float)a/b     d=2.50    Type casting (or) explicit conversion

C – TYPE CASTING EXAMPLE PROGRAM : 

To enter base and height of a triangle and to calculate its area.

To enter radius of a circle and to calculate its area.

 

 

Prev Next