Type Casting

Type Casting: The type casting is to change variable data type to another when you want.Consider a setuation like you have two integer value a=3 and b=4 and you need to find the median of those value. if you add both this ,a+b number total is 7.If you divide (a+b)/2 the result become 3 because integer can not hold decimal points but the result should be 3.5. Type casting is used to get rid of this kind setuation.

Let's see an example
int main(){
  int a = 3;
  int b = 4;
  int total = a + b;
  float median1 = total / 2;
  printf("%f \n", median1);//'\n' is used to go to new line.
  float median2 = (float)total / 2; //type casting.
  printf("%f \n", median2);
  printf("%.2f \n", median2); // .2f used for printing upto two decimal point.

  return 0;