Thuta Learning
BasicProgrammingbeginner

Data Types

Relax. We'll talk through this in plain words — no textbook voice.

A data type defines what kind of data a variable can hold. Getting the type right is what keeps memory usage, calculations, and output formatting correct.

c
#include <stdio.h>

int main() {
  int items = 5;
  double distance = 12.7564;
  char initial = 'T';

  printf("Items: %d
", items);
  printf("Distance: %.3lf km
", distance);
  printf("Initial: %c", initial);
  return 0;
}

int holds a whole number, double holds a decimal number with higher precision than float, and char holds a single character.

You should see
Items: 5 Distance: 12.756 km Initial: T

Info

For decimal values where precision matters in calculations, it's better to use double.

Easy traps

  • Watch out for integer division. Computing 5 / 2 as int gives you just 2, not 2.5. If you need a decimal result, write it as 5.0 / 2.