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

Discussion

What is the output of this C code?

int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}

 

  • A.10,10
  • B.10,11
  • C.11,10
  • D.11,11

Answer: D

Correct answer: 11,11

ptr holds the address of a, so *ptr += 1 increments a itself - there is only one object, reached by two names. Both print as 11. Note also the /n in the format string, which is a forward slash and the letter n rather than an escape, so it appears literally instead of starting a new line.

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

Post your comment

Please log in or register to post a comment.