basics · beginner · ~10 min
Memorize the type sizes on the platform you build on.
Record the size in bytes of the fundamental C types on the platform you compile for.
Implement void print_sizes(int *out) that fills out[0..5] with sizeof applied to char, short, int, long, size_t, and void*, in exactly that order. Write nothing else; do not print.
A pointer out to an array of at least 6 ints.
No return value. After the call: out[0]=sizeof(char), out[1]=sizeof(short), out[2]=sizeof(int), out[3]=sizeof(long), out[4]=sizeof(size_t), out[5]=sizeof(void*).
print_sizes(out); -> out == {1, 2, 4, 8, 8, 8} (typical 64-bit Linux/macOS)
long is 8 bytes on LP64 (Linux/macOS) but 4 bytes on LLP64 (Windows). The grader checks against the build platform's own sizeof, so report the real values.printf — just store the sizes into out.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.
A pointer out to at least 6 ints.
No return value; out[0..5] set to sizeof of char, short, int, long, size_t, void* in order.
No printf; just write to out. Cast each sizeof (a size_t) to int.
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.