What will be the output of the program If the integer is 4bytes long?
#include <stdio.h>
int main()
{
int ***r, **q, *p, i=8;
p = &i;
q = &p;
r = &q;
printf("%d, %d, %d\n", *p, **q, ***r);
return 0;
}
Answer: A
Correct answer: 8, 8, 8
Each level of indirection is undone by one dereference. p points to i, q points to p, and r points to q.
So *p reaches i directly; **q goes through p to i; and ***r goes through q and p to i. All three arrive at the same object and print 8. The distractors offer addresses, which would appear only if fewer dereferences were applied than there are levels of indirection.
Please log in or register to report this question.