← Debugging with gdb/lldb & Memory-Checking Tools

Bounded Index

easy

Recall from Module 2 that C does no bounds checking at all – arr[index] for an out-of-range index silently reads whatever memory happens to be there. Implement get_at to guard against that: assert that index is within [0, length) before indexing, then return arr[index].

Every test case here passes a valid index, so the assert will never actually fire – that’s normal. Its job isn’t to change what correct input does; it’s to make the function’s requirement explicit and enforced, so a future caller passing an invalid index gets an immediate, clear failure at this exact line, instead of a silent out-of-bounds read that might not misbehave visibly until much later.

Your solution

"Run" uses the sample stdin ("5\n10 20 30 40 50\n2"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution