codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C type conversion

C type conversion

Implicit and explicit casts.

Mixed types convert automatically, and integer division drops decimals. Cast with (float) to force a decimal result.

Example code

#include <stdio.h>
int main() {
  int a = 5, b = 2;
  printf("%d\n", a / b);
  printf("%.2f\n", (float) a / b);
  return 0;
}

Run this code in the online editor

← C data typesC constants →