pointers-memory · beginner · ~15 min
Verify a buffer is zeroed.
Check whether every element of an array is zero.
Implement int all_zero(const int *a, int n) that returns 1 if all of the first n elements are 0, otherwise 0. No main — the grader calls it.
a — pointer to an int array. n — the number of elements to inspect (may be 0).
Returns 1 if every element is 0 (or n == 0), else 0.
all_zero({0,0,0}, 3) -> 1
all_zero({0,1,0}, 3) -> 0
all_zero(a, 0) -> 1 (vacuously true)
n == 0: returns 1 (no element violates the condition).a — int array; n — count to inspect (may be 0).
1 if all n elements are 0 (or n==0), else 0.
int all_zero(const int *a, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.