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
#include<stdio.h>
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;
}
Output:
  3
  3.5
  3.50   

Best way of learing

Self learing is the best learing in the world. Discover yourself first then will get what you are And what you want to do .It will push you for self learing.

Why you need to learn coding?

Coding will play a vital role in one's life . It will help to open a new window of thinking . You can think better way than past . It helps to organise all the thing in better way .