Step 1 of 7
Sizes and limits
C only promises minimum sizes. On today's common platforms:
| Type | Usual size | Range (signed) |
|---|---|---|
char |
1 byte | -128 to 127 |
short |
2 bytes | about ±32 thousand |
int |
4 bytes | about ±2.1 billion |
long |
4 or 8 bytes | depends on the platform! |
long long |
8 bytes | about ±9.2 × 10¹⁸ |
long is 8 bytes on 64-bit Linux and macOS, but 4 bytes on Windows and on 32-bit systems (including the WebAssembly this site runs on). Code that assumes one or the other breaks when it moves. That's why professional code uses the exact-width types you'll meet in a few steps.
<limits.h> gives the real limits for the platform you compile on: INT_MAX, INT_MIN, LLONG_MAX, UINT_MAX, CHAR_BIT (bits in a byte, 8 everywhere you'll ever work).
Your turn: print the largest int, then the smallest.