Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.