Skip to main content

Practice ยท 4 of 4

Fix: Uninitialized Accumulator

sum_evens(const int *a, int n) reads total before initializing it. Fix the function so it returns the sum of even elements. ``c int sum_evens(const int *a, int n) { int total; for (int i = 0; i < n; i++) if (a[i] % 2 == 0) total += a[i]; return total; } ``

Difficulty: beginner

Back to lesson: Practice: Warning Forensics