pointers-memory · intermediate · ~15 min

Dereference twice

Follow two levels of indirection.

Challenge

Follow two levels of indirection: a pointer to a pointer to an int, down to the int itself.

Task

Implement int deref2(int **pp) that returns the int reached by dereferencing pp twice (**pp). No main — the grader calls it.

Input

pp — a pointer to an int*, which in turn points to a valid int.

Output

Returns the int value at **pp.

Example

int x = 5; int *p = &x;
deref2(&p)   ->   5
x = 99;
deref2(&p)   ->   99

Input format

pp — a pointer to an int* that points to a valid int.

Output format

The int value at **pp.

Starter code

int deref2(int **pp) {
    /* TODO */
    return 0;
}

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