pointers-memory · intermediate · ~15 min
Use pointer increment and two-pointer ranges (like C++ iterators).
Sum a slice of an int array described by a begin/end pointer pair (like C++ iterators).
Implement long sum_walk(const int *begin, const int *end) that returns the sum of the ints in the half-open range [begin, end). No main — the grader calls it.
Two pointers into the same array: begin (inclusive) and end (exclusive). The range may be empty (begin == end).
The sum of the elements from begin up to but not including end, as a long.
sum_walk(a, a+5) where a={1,2,3,4,5} -> 15
sum_walk(a, a) -> 0
sum_walk(a+1, a+4) where a={1,2,3,4,5} -> 9
begin == end: the range is empty, return 0.Two pointers begin (inclusive) and end (exclusive) into one int array.
The sum of the elements in [begin, end) as a long.
Use pointer arithmetic, no separate length; empty range returns 0.
#include <stddef.h>
long sum_walk(const int *begin, const int *end) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.