C comparison operators in expression
Example 1 : Illustration of Indirect or Invisible If
More Theory : Click Here : Indirect If Statement
We have seen basic concept about “Indirect Use of If Statement”. Now we are focusing on more and more short tutorials before solving MCQ’s .
#include<stdio.h> int main() { int a = 40; int b = 30; int c; c = !(a>=0) >= 0; printf("%d",c); return(0); }
Output :
1
How to Make use of Comparison Statement inside If Statement :
- While Solving such a Long expression , First Scan Expression from Left to Right .
- Solve Expression bounded in Pair of ( ) .
Step 1 :
- Always Solve Bracket First
c = !(a>=0) >= 0
Step 2 :
- a>=0 is True
- So Replace “a>=0” by 1
c = !1 >= 0
Step 3 :
- NOT Operator has Higher Priority Than >= Operator .
- !1 = 0
- Replace “!1” by “0”
c = 0 >= 0
Step 4 :
- Obviously 0 >= 0 is True Condition
- Replace Whole Expression by 1
c = 1
Thus C = 1