pointers-memory · intermediate · ~5 min
Follow two levels of indirection.
Follow two levels of indirection: a pointer to a pointer to an int, down to the int itself.
Implement int deref2(int **pp) that returns the int reached by dereferencing pp twice (**pp). No main — the grader calls it.
pp — a pointer to an int*, which in turn points to a valid int.
Returns the int value at **pp.
int x = 5; int *p = &x;
deref2(&p) -> 5
x = 99;
deref2(&p) -> 99
Drill: practice one contract before combining it with other skills.
pp — a pointer to an int*, which in turn points to a valid int.
Returns the int value at **pp.
pp and *pp are non-NULL and point to live objects; **pp is a readable int. Do not modify either pointer or the int.
int deref2(int **pp) {
/* TODO */
return 0;
}
Following only one level and confusing an int pointer with an int value.
Zero, negative and extreme int values; pointer redirection between calls.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.