C Basics · beginner · ~10 min

Data types

Pick the right primitive type for the data at hand.

Lesson

C's built-in types fall into a few groups:

  • Integer: char, short, int, long, long long plus unsigned variants. Sizes are platform-dependent; use <stdint.h> (int32_t, uint64_t) when you need exact widths.
  • Floating-point: float (32-bit), double (64-bit), long double (larger, varies).
  • _Bool (or bool after #include <stdbool.h>), with true / false.
  • void for "no value" (e.g., a function returning nothing).

Code examples

#include <stdint.h>
#include <stdbool.h>
uint32_t pixels = 1024 * 768;
bool     enabled = true;
double   ratio = pixels / 2.0;

Common mistakes

  • Assuming int is 32 bits everywhere — it usually is, but not on every platform.
  • Mixing signed and unsigned in comparisons (-1 < 1U is false because of integer promotion).