basics · beginner · ~15 min

Fits in a byte?

Reason about the range of a fixed-width type.

Challenge

Implement int fits_in_uint8(int n) returning 1 if n is in the range 0..255 (the range of an unsigned 8-bit value), else 0.

Starter code

int fits_in_uint8(int n) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.