C Programming - Expressions - Discussion
Discussion Forum : Expressions - True / False Questions (Q.No. 2)
2.
The expression of the right hand side of || operators doesn't get evaluated if the left hand side determines the outcome.
Answer: Option
Explanation:
Because, if a is non-zero then b will not be evaluated in the expression (a || b)
Discussion:
9 comments Page 1 of 1.
Rohit said:
3 years ago
Here, The right side will get evaluated when the left side is non-zero. So ideally answer should be false. In the case of && it should be true.
Saurabh said:
7 years ago
@Sathish.
According to this condition, the answer would be False.
So, the correct answer is B.
According to this condition, the answer would be False.
So, the correct answer is B.
(1)
Rahul said:
8 years ago
I too have same doubt @Sathish.
Can anyone explain about what would be the evaluation process if left side of || is false?
Can anyone explain about what would be the evaluation process if left side of || is false?
SATHISH KUMAR said:
8 years ago
What if the left hand side is false? The right side gets evaluated.
Luis said:
1 decade ago
This is false, the order (direction) of evaluation is dependent on the compiler, in practice the order is random.
Valluri lakshmi bharathi said:
1 decade ago
logical OR ||.
ex : int a=10,b=0;
if(a==10 || a/b==10)
In this expression, a=10 is true and second expression a/b=10 is false.
Here,we need to understand that (true || anything(true or false)) is always true.
So,second expression is not evaluated. And the value of entire expression is true.
ex : int a=10,b=0;
if(a==10 || a/b==10)
In this expression, a=10 is true and second expression a/b=10 is false.
Here,we need to understand that (true || anything(true or false)) is always true.
So,second expression is not evaluated. And the value of entire expression is true.
Rupinderjti said:
1 decade ago
But if we have && of high precedence than that of ||,will it's execution and consideration be also get skipped.
eg: x=c||a++&&++b;(if c=1,then does it mean that && having high priority than pipeline will get skipped?.)
eg: x=c||a++&&++b;(if c=1,then does it mean that && having high priority than pipeline will get skipped?.)
Swagath9849636443 said:
1 decade ago
MAya Ray ! refer about logical operators. it depends on true or false only. and return ans as 1 or 0 only. So if first term is true then T or F is T i.e 1. The case if first term false then 2nd term would be evaluated. because F or F = F;
F or T = T;
If 1st term T then ans is T i.e. T or T = T;
T or F = T;
F or T = T;
If 1st term T then ans is T i.e. T or T = T;
T or F = T;
Maya Ray said:
1 decade ago
I didn't get this answer. Why the right hand side won't be evaluated if the left side is non-zero? whats the relation I didn't get. Kindly reply anyone.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers