pointers-memory · beginner · ~15 min

Sum an array with a pointer

Iterate an array by moving a pointer.

Challenge

Implement long sum_via_ptr(const int *a, int n) summing n elements by advancing a pointer (no indexing).

Starter code

long sum_via_ptr(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.