C Programming - Expressions - Discussion
Discussion Forum : Expressions - Find Output of Program (Q.No. 10)
10.
What will be the output of the program?
#include<stdio.h>
int main()
{
int a=100, b=200, c;
c = (a == 100 || b > 200);
printf("c=%d\n", c);
return 0;
}
Answer: Option
Explanation:
Step 1: int a=100, b=200, c;
Step 2: c = (a == 100 || b > 200);
becomes c = (100 == 100 || 200 > 200);
becomes c = (TRUE || FALSE);
becomes c = (TRUE);(ie. c = 1)
Step 3: printf("c=%d\n", c); It prints the value of variable i=1
Hence the output of the program is '1'(one).
Discussion:
3 comments Page 1 of 1.
Anish Kumar said:
9 years ago
@Kaushal
Yes, you are right, both are a relational operator but > has higher precedence than ==.
Yes, you are right, both are a relational operator but > has higher precedence than ==.
Kaushal 10dell said:
1 decade ago
Answer is right @Eshant.
But (i think).
According to hierarchy of operators '>' is to be calculated before '||'.
So after checking b>200 another check that is a==100 is performed.
In short both conditions are checked.
But (i think).
According to hierarchy of operators '>' is to be calculated before '||'.
So after checking b>200 another check that is a==100 is performed.
In short both conditions are checked.
Eshant Sahu said:
1 decade ago
c = (a == 100 || b > 200);
Now , when the left side condition of the '||' operator is true, it will not check for right side condition,
So, c=(TRUE)
c=1;
Hence output of the program is '1'(one).
Now , when the left side condition of the '||' operator is true, it will not check for right side condition,
So, c=(TRUE)
c=1;
Hence output of the program is '1'(one).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers