basics · intermediate · ~15 min
Accumulate persistent state safely.
Implement long running_total(int x) that adds x to an internal running sum (starting at 0) and returns the new total, using a static local.
long running_total(int x) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.