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 1 of 4.
Rohan kumar said:
3 years ago
You explained very well @Nanikanchari.
Here the condition is ;
int a = 500, b = 100, c;
if(!a >= 400)
So let me take only a>=400 okay. and a value is 500 we know;
So, it will be like 500>=400, so it is true. hence value '1' it will consider in the if() condition.
but we have '!' operator in front of it, so the value will be '0'.
Here the condition is ;
int a = 500, b = 100, c;
if(!a >= 400)
So let me take only a>=400 okay. and a value is 500 we know;
So, it will be like 500>=400, so it is true. hence value '1' it will consider in the if() condition.
but we have '!' operator in front of it, so the value will be '0'.
(6)
VINEETHA said:
8 years ago
Than why mention b=300 here?
(3)
Peachu said:
3 years ago
I can't understand this code. Please, anyone, explain me.
(1)
AKSHAY said:
7 years ago
As per my knowledge, it is;
int a=50, b,c;
if(a<=40)
b=100;
C=200;
printf ("%d %d ",b,c);
int a=50, b,c;
if(a<=40)
b=100;
C=200;
printf ("%d %d ",b,c);
(1)
Akanksha Reddy said:
8 years ago
The c value is clearly mentioned out from the if loop. Hence as if the condition is failed since it takes only the c value and initial value of b. Hence the option is D.
X-hedow said:
1 decade ago
! means not equal to which in the case is 500.
Then I think we should start considering 'b' and 'c'.
Therefore 'b' is true.
But as for 'c' I do not understand where it's value came from.
Then I think we should start considering 'b' and 'c'.
Therefore 'b' is true.
But as for 'c' I do not understand where it's value came from.
Bhaskar said:
1 decade ago
What is the difference between !(a<=40) and (!a<=40)?
Ratna said:
1 decade ago
When there is no body part, loop ended at the immediate semicolon.
Denny said:
1 decade ago
What is meant by 500?
Jinal said:
1 decade ago
Not understand what meaning if (!a>=400) please explain it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers