Skip to main content

Practice ยท 4 of 5

Initialize Everything

CHALLENGE
Difficulty: advanced+25 XP

Implement int sum_known(const int *a, size_t n) that totals the array โ€” and if n is 0 returns 0. The trap: a wrong answer pattern is returning an uninitialized accumulator 'sometimes works'. Then implement int *find_or_null(int *a, size_t n, int v) returning the first match or NULL โ€” the two functions together exercise init-discipline and null contracts.

Back to lesson: Practice: UB and Optimizer Drills