What is printed by this C code: int x = 7; int *p = &x; int **q = &p; **q = 9; printf(“%d”, x);?
Correct answer C. 9
Explanation
q holds the address of p, and p holds the address of x. *q therefore gives p, and **q gives the object p points to, which is x. Assigning 9 through **q changes x itself. Pointers to pointers are used when a function must change a caller's pointer, for example a function that allocates memory and stores the new address in an argument.
Answer checked How we write and check questions
Discussion