basics · beginner · ~10 min
Memorize the type sizes on the platform you build on.
Implement void print_sizes(int *out) that fills out[] with the sizeof of char, short, int, long, size_t, void* in that order. Six entries.
Pen testers and reverse engineers must know type sizes at sight. A 4-byte signed integer overflow at INT_MAX is the start of half the integer-overflow CVEs in C.
out of at least 6 ints.
out[0..5] populated.
No printf inside; just write to out.
void print_sizes(int *out) { /* TODO */ }
Assuming int is 4 bytes everywhere — it usually is on 32/64-bit Linux/macOS but not on every embedded platform.
LP64 (Linux/macOS): long is 8 bytes; LLP64 (Windows): long is 4 bytes.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.