C/C++ Arena

Step 7 of 10

Pointers to pointers

A pointer is a variable too, so it has an address. int **pp is a pointer to a pointer to int. You need one when a function must change which address a pointer holds.

void point_at_max(int *a, int n, int **out) {
    *out = &a[0];
    for (int i = 1; i < n; i++)
        if (a[i] > **out) *out = &a[i];
}

Your turn: write void advance(const char **s) that moves the caller's string pointer past any leading spaces. After advance(&p) with p pointing at " go", p should point at "go".

Previous: Strings through pointers Next: const and pointers