Skip to main content

Practice · 5 of 5

Unspecified Order, Deterministically Handled

CHALLENGE
Difficulty: advanced+25 XP

The counters below are already in your editor: ``c static int calls_a = 0, calls_b = 0; static int bump_a(void) { return ++calls_a; } static int bump_b(void) { return ++calls_b; } ` Implement int observed_sum(void) returning bump_a() + bump_b() (one call to each). Then implement int order_safe(void) returning the same total but computed in separate statements so it never depends on evaluation order. Also implement int counters_match_sum(int s) returning 1 iff calls_a + calls_b == s`.

Back to lesson: Practice: Sequencing and Lifetime Drills