Home » C Programming » Decision Making » Question
  1. Which of the following is the correct output for the program given below?
    #include <stdio.h>
    int main ( )
    {
    int x = 0, y = 1, z = 3;
    * ( ( x ) ? &y : &x = x ? y :z;
    printf ("%d %d %d\n", x, y, z);
    return 0;
    }
    1. 0 1 3
    2. 1 2 3
    3. 3 1 3
    4. 1 3 1
Correct Option: C

Step 1: int x=0, y=1, z=3; here variable x, y, and z are declared as integer type and initialized to 0, 1, 3 respectively.

Step 2: *((x) ? &y : &x) = x ? y : z; The right side of the expression(x?y:z) becomes (0?1:3). Hence it return the value '3'.

The left side of the expression *((x) ? &y : &x) becomes *((0) ? &y : &x). Hence this contains the address of the variable x *(&x).

Step 3: *((x) ? &y : &x) = x ? y : z; Finally this statement becomes *(&x)=3. Hence the variable a has the value '3'.

Step 4: printf("%d, %d, %d\n", x, y, z); It prints "3, 1, 3".



Your comments will be displayed only after manual approval.