pointers-memory · beginner · ~15 min

Is an index in bounds?

Write the bounds check that prevents dangling/out-of-range access.

Challenge

Implement int index_in_bounds(int idx, int len) returning 1 if idx is a valid index into a len-element array (0 <= idx < len), else 0.

Starter code

int index_in_bounds(int idx, int len) {
    /* TODO */
    return 0;
}

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