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;
}
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.
Jasson said:
1 decade ago
May be the answer is wrong because there is no begin and end brackets for if loop in that case only first statement executed and second one may be garbage value i.e. in my opinion option B is correct. If I wrong please comment.
Botta said:
1 decade ago
@Nikhil
you are not supposed to take your own values to 'a' since 500 is already assigned to it.
you are not supposed to take your own values to 'a' since 500 is already assigned to it.
Nikhil said:
1 decade ago
@Naveen.
Hello, i want to ask one doubt regarding NOT logic operator.
Is !a=0 , for a having value other than zero. Like a=300?
But @levin max
Said that !a>=400 as a<=400. If this is right. then for a=300 the IF condition gets TRUE. and the value b=300 gets assigned, and the output will be displayed as b=300 and c=200.
So please clarify me REGARDING not OPERATOR.
Hello, i want to ask one doubt regarding NOT logic operator.
Is !a=0 , for a having value other than zero. Like a=300?
But @levin max
Said that !a>=400 as a<=400. If this is right. then for a=300 the IF condition gets TRUE. and the value b=300 gets assigned, and the output will be displayed as b=300 and c=200.
So please clarify me REGARDING not OPERATOR.
Biswajit said:
1 decade ago
@Naveen.
Your explanation is right, "!" it check the value whether it is zero or not, if Zero it return 1 otherwise 0.
Your explanation is right, "!" it check the value whether it is zero or not, if Zero it return 1 otherwise 0.
Suneetha said:
1 decade ago
Because the conidition is failed. So we already assigend the value b=100 so it will print.
Ganga said:
1 decade ago
Why b value gets 100 any one explain me?
Venkat said:
1 decade ago
What does this symbol "!" in the above program? can any one explain clearly?
Levin max said:
1 decade ago
Take !a>=400 as a<=400.
Naveen said:
1 decade ago
! is having highest preference
so !500 is 0
>= is next to ! in preference
so 0 >= 400 is 0(flase)
;)
so !500 is 0
>= is next to ! in preference
so 0 >= 400 is 0(flase)
;)
Vino said:
1 decade ago
I want the meaning of if(!a>=400).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers