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

Discussion

What is the output of this C code?

void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}

 

  • A.Different address is printed
  • B.1   2
  • C.Same address is printed.
  • D.1   1

Answer: C

Correct answer: Same address is printed.

r holds the address of p, so *r is p itself, and p was set from a, which decays to the address of its first element. So *r and a print the same address. Note that the levels are now consistent, unlike the previous question, which is why this one compiles.

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

Post your comment

Please log in or register to post a comment.