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

Discussion

What is the output of this C code?

void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **m);
}

 

  • A.5   5   5
  • B.5  5 junk value
  • C.5 junk value
  • D.Run time error

Answer: A

Correct answer: 5 5 5

Each dereference removes one level. k is 5; p holds the address of k, so *p is 5; and m holds the address of p, so *m is p and **m is 5. All three names reach the same object by paths of different length, which is the whole point of the double pointer.

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

Post your comment

Please log in or register to post a comment.