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 = 600, y = 200, z;
    if (!x >= 400)
    y = 300;
    z = 450;
    printf ("y = %d z = %d\n", y, z);
    return 0;
    }
    1. y = 300 z = 200
    2. y = 200 z = garbage
    3. y = 300 z = garbage
    4. y = 200 z = 450
    5. y = 200 z = 600
Correct Option: D

Initially variables x = 600, y = 200 and c is not assigned.

Step 1: if(!x >= 400)
Step 2: if(!600 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable z is assigned to a value '450'.
Step 6: printf("y = %d z = %d\n", y, z); It prints value of y and z.
Hence the output is "y = 200, z = 200"



Your comments will be displayed only after manual approval.