How to use basic data types

Use integer types

char, short, int, long, and long long have implementation-defined ranges. Unsigned variants cannot represent negative values.

int count = 42;
long population = 1000000L;
unsigned int flags = 3U;

Use floating types

float, double, and long double represent finite approximations. Prefer double for ordinary calculations.

double distance = 12.75;
printf("%.2f\n", distance);

Measure with sizeof

sizeof returns a byte count as size_t. Do not assume that an int is always four bytes.

printf("int: %zu bytes\n", sizeof(int));
printf("double: %zu bytes\n", sizeof(double));

Use fixed-width types when required

Include stdint.h when a file format or protocol requires an exact width. Use stdbool.h for the portable C17 spelling bool.

#include <stdbool.h>
#include <stdint.h>

bool ready = true;
uint32_t packet_id = UINT32_C(100);