C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Find Output of Program (Q.No. 3)
3.
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;
}
b = 300 c = 200
b = 100 c = garbage
b = 300 c = garbage
b = 100 c = 200
Answer: Option
Explanation:

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"

Discussion:
33 comments Page 3 of 4.

Ratna said:   1 decade ago
When there is no body part, loop ended at the immediate semicolon.

Santosh said:   1 decade ago
In step 4 if the condition is failed then why it is taking c=200.

Jinal said:   1 decade ago
Not understand what meaning if (!a>=400) please explain it.

Bhaskar said:   1 decade ago
What is the difference between !(a<=40) and (!a<=40)?

Surabhi agarwal said:   9 years ago
Why are we assigning c = 200 when if the condition fails?

Peachu said:   3 years ago
I can't understand this code. Please, anyone, explain me.
(1)

Vijaya zambre said:   2 decades ago
b = 300;

Why this step is mentioned there?

Ganga said:   1 decade ago
Why b value gets 100 any one explain me?

Vino said:   1 decade ago
I want the meaning of if(!a>=400).

Levin max said:   1 decade ago
Take !a>=400 as a<=400.


Post your comments here:

Your comments will be displayed after verification.