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

Discussion

What is the output of this C code?    

void main()
    {
        int x = 4, y, z;
        y = --x;
        z = x--;
        printf("%d%d%d", x,  y, z);
    }

 

  • A.3  2  3
  • B.2  3  3
  • C.3  2  2
  • D.2  3  4

Answer: B

Correct answer: 2 3 3

Follow the two statements:

  • y = --x; - pre-decrement, so x becomes 3 and y takes that new value, 3.
  • z = x--; - post-decrement, so z takes the old value 3 and x then becomes 2.

Printing x, y, z gives 2 3 3.

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

Post your comment

Please log in or register to post a comment.