Machine-translated by Google. Questions are authored in English.
Top

Discussion

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;
}

 

  • A.8, 8, 8
  • B.4000, 4002, 4004
  • C.4000, 4004, 4008
  • D.4000, 4008, 4016

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.