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

Discussion

What is the output of this C code?

#include <stdio.h>
    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 and a are two names for the same object. *ptr += 1 increments that object, and both expressions therefore read 11.

Note the format string ends in /n, a forward slash, not the escape \n. So the two characters are printed literally and no newline is emitted - a typographical slip that changes the output's appearance without affecting the values, which are what the question asks for.

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

Post your comment

Please log in or register to post a comment.