ExamVeda
Login
Home
This question belongs to C Program C Fundamentals
C Fundamentals
?

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int x = 2, y = 0;
    int z = (y++) ? y == 1 && x : 0;
    printf("%d\n", z);
    return 0;
}

Answer & Solution
Correct Answer: Option A
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Vinita
Vinita 2 years ago
Initialization:int x = 2, y = 0; initializes x to 2 and y to 0.
Ternary Operation:The ternary operation int z = (y++) ? y == 1 && x : 0; evaluates as follows:
(y++): y++ increments y after its value is used in the expression. So, at this point:
The value of y++ is 0 (since y is initially 0).
After this operation, y becomes 1.
Since (y++) evaluates to 0 (which is false), the ternary operation will take the false branch, which is 0.