pointers-memory · beginner · ~15 min

Nth element via pointer arithmetic

Understand that a[n] is *(a + n).

Challenge

Implement int nth(const int *a, int n) returning a[n] using pointer arithmetic (*(a + n)), not the indexing operator.

Starter code

int nth(const int *a, int n) {
    /* TODO: use *(a + n) */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.