Control Instructions

Q1:
What will be the output of the program?
#include<stdio.h>
int main()
{
    int a = 500, b = 100, c;
    if(!a >= 400)
        b = 300;
    c = 200;
    printf('b = %d c = %d\n', b, c);
    return 0;
}

A b = 300 c = 200

B b = 100 c = garbage

C b = 300 c = garbage

D b = 100 c = 200

ANS:A - b = 300 c = 200

Initially variables a = 500, b = 100 and c is not assigned. Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable c is assigned to a value '200'.
Step 6: printf('b = %d c = %d\n', b, c); It prints value of b and c.
Hence the output is 'b = 100 c = 200'



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.