C Programming • C17 baseline, standards-specific features labeled
C Data Types and Object Sizes
Choose types by the values and guarantees your program needs, not by assumptions about machine sizes.
C provides integer, floating-point, character, and derived types. Exact widths are not guaranteed for every basic type on every platform. Use sizeof to inspect storage and the fixed-width types from stdint.h when a specific bit width is required.
Example
#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>
int main(void) {
int count = 12;
uint32_t packet_id = 4000;
printf("count=%d, bytes=%zu\n", count, sizeof count);
printf("packet=%" PRIu32 "\n", packet_id);
return 0;
}
What to expect
The size of int is platform-dependent; uint32_t, when provided, has exactly 32 value bits.
Key idea: Match printf conversion specifiers to the actual argument types and use <inttypes.h> macros for portable fixed-width formatting.