Typecasting allows us to convert one data type into other. In C language, we use cast operator for typecasting which is denoted by (type).

Syntax:



  1. (type)value; 

Without Type Casting:


  1. int f= 9/4;  
  2. printf("f : %d\n", f );//Output: 2

  

With Type Casting:


  1. float f=(float) 9/4;  
  2. printf("f : %f\n", f );//Output: 2.250000  



Type Casting example

Let's see a simple example to cast int value into the float.



  1. #include<stdio.h>  
  2. int main(){  
  3. float f= (float)9/4;    
  4. printf("f : %f\n", f );    
  5. return 0;  
  6. }      

Output:

f : 2.250000


Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya