Tsallaka zuwa abun ciki
Justice Tech School

Type Casting

Cast with (type). Conversions between integer and floating types can lose data.

Example
#include <stdio.h>

int main(void) {
  double d = 9.99;
  int n = (int) d;
  char c = (char) 66;
  printf("%d %c %.2f\n", n, c, (double) 7 / 2);
  return 0;
}

Result

9 B 3.50

Exercise

Cast syntax.

() 9.99

Quiz Test

What does (int) 9.99 give?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.