basics · beginner · ~15 min

Clamp an exit code

Reduce a value modulo 256 with correct negative handling.

Challenge

Process exit codes are a byte (0-255). Implement int byte_exit(int n) returning n reduced into 0-255 (wrapping like the shell does), correct for negative n too.

Starter code

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

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