Primitive Types
C's primitive types are the built-in integers, floating-point numbers, and void. Their sizes are minimums in the standard, not fixed widths, which is why portable code uses <stdint.h> when it needs an exact number of bits.
Detailed Explanation
The standard integer types are char, signed char, unsigned char, short, int, long, and long long, plus the unsigned variants of the last four. char is a separate type from signed char and unsigned char; whether a plain char is signed is implementation-defined. The floating types are float, double, and long double. _Bool (or bool from <stdbool.h> in C99 and later, and a keyword in C23) holds 0 or 1. void is an incomplete type used for functions that return nothing and for untyped pointers.
The standard does not say int is 32 bits. It says int is at least 16 bits, long is at least 32, and long long is at least 64, and that each rank is at least as wide as the one below it. On a 64-bit LP64 Unix machine — Linux, macOS — int is 32 bits and long is 64. On 64-bit Windows (LLP64), int and long are both 32 bits and long long is 64. Code that stores a pointer in an int or assumes long can hold a file offset will compile and then break when it crosses that line.
When you need a width, say so. <stdint.h> provides int8_t, int16_t, int32_t, int64_t and their unsigned twins where the implementation supports them, plus int_fastN_t and int_leastN_t when any type of at least N bits will do. <stddef.h> gives size_t for sizes and ptrdiff_t for pointer differences. <stdbool.h> gives bool, true, and false without you inventing an int flag convention.
Integer promotions and the usual arithmetic conversions decide the type of a + b when a and b differ. A char or short in an expression is first promoted to int if int can hold every value of the original type, otherwise to unsigned int. Mixing signed and unsigned then follows rank. The result can surprise you: -1 < 1u is false, because -1 is converted to a large unsigned value before the comparison.
sizeof reports the size in bytes. A byte is CHAR_BIT bits, which is at least 8 and is 8 on every machine you will meet in application code. Use sizeof instead of hard-coded 4 or 8.
Code Examples
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
int main(void)
{
printf("char=%zu int=%zu long=%zu long long=%zu\n",
sizeof(char), sizeof(int), sizeof(long), sizeof(long long));
/* typical LP64: char=1 int=4 long=8 long long=8
typical Windows LLP64: char=1 int=4 long=4 long long=8 */
int32_t count = 42; /* exactly 32 bits, or the header would not exist */
uint64_t id = 1; /* use unsigned when the value cannot be negative */
bool ok = true;
printf("%d %llu %d\n", count, (unsigned long long)id, ok);
/* prints: 42 1 1 */
return 0;
}#include <stdio.h>
int main(void)
{
signed char sc = -1;
unsigned int u = 1u;
/* sc promotes to int -1, then -1 is converted to unsigned before `<`. */
printf("%d\n", sc < u); /* prints: 0 (false) */
printf("%d\n", (int)sc < (int)u); /* prints: 1 (the comparison you meant) */
return 0;
}Common Gotchas
`int` is not "the 32-bit type"
it is at least 16 bits. Use `int32_t` or `long` with a documented assumption when the range matters.
Plain `char` may be signed or unsigned
on ARM it is often unsigned. Write `signed char` or `unsigned char` when you mean a small integer rather than a character.
Storing a pointer in `int` truncates on LP64
use `intptr_t` or `uintptr_t` from `<stdint.h>` if you must round-trip an address through an integer.
`_Bool` converts any non-zero to `1`
`bool b = 2;` stores `1`. That is different from `int b = 2`.