Type Casting or Type Conversion in C Language

Type casting allows us to convert one data type into other.

Converting one datatype into another is known as type casting or, type-conversion.

Explicit Type Conversion

The type conversion performed by the programmer by posing the data type of the expression of specific type is known as explicit type conversion. 

Syntax

(type)value;

Example

#include <stdio.h>

int main() {
  //Without Type Casting:
  int f = 9 / 4;
  printf("f : %d\n", f); //Output: 2 

  //With Type Casting:
  float k = (float) 9 / 4;
  printf("k : %f\n", k); //Output: 2.250000  

  return 0;
}

Implicit Type Conversion

Also known as ‘automatic type conversion’.

When the type conversion is performed automatically by the compiler without programmers intervention, such type of conversion is known as implicit type conversion or type promotion.

int x;
for(x=97; x<=122; x++)
{
    printf("%c", x);   /*Implicit casting from int to char thanks to %c*/
}