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);
}
Answer: D
Correct answer: 2 3 3
Follow the two statements:
y = --x;- pre-decrement, soxbecomes 3 andytakes that new value, 3.z = x--;- post-decrement, soztakes the old value 3 andxthen becomes 2.
Printing x, y, z gives 2 3 3.
Please log in or register to report this question.