C - Data Type Type casting

Introduction

You can cast from one type to another type.

For example you can cast from float to int type.

float debt;
int d = (int)debt 

In the preceding line, the float variable debt is typecast to an int value.

The int in parentheses directs the compiler to treat the value of debt as an integer.

Demo

#include <stdio.h> 

int main() //w  w w. j ava 2s .c  o m
{ 
      int a,b; 
      float c; 

      printf("Input the first value: "); 
      scanf("%d",&a); 
      printf("Input the second value: "); 
      scanf("%d",&b); 
      c = a/b; 
      printf("%d/%d = %.2f\n",a,b,c); 

      c = (float)a/(float)b; 
      printf("%d/%d = %.2f\n",a,b,c); 

      return(0); 
}

Result

You type cast variables a and b in the equation, allowing the compiler to treat them as floating-point numbers.

Therefore, the result is what it should be.