How to solve expression containing comparison and assignment operators ?
Example : Illustration of Indirect or Invisible If [ Click Here : Indirect If Statement ]
#include<stdio.h> void main() { int a = 40 , b = 30 ,c; c = !a<=!(c=b); printf("%d",c); }
Output :
1
How ?
Step 1 :
- Always Solve Bracket First
- (c = b) : Assignment Operator Assigns value of RHS to LHS i.e Assigns value of b to c
- Replace “(c=b)” by 30
c = !a<=!30;
Step 2 :
- “Not” Operator has Higher Priority Than “<=” Operator.
- !a= !40 = 0
- Replace “!a” by “0″ as we calculated .
c = 0<=!30
Step 3 :
- As “c = 0<=!30″ contain again Two Operands , Again scan Expression from we have now Two Operators “!” and “<=”.
- “Not” Operator has Higher Priority so
- !30 = 0
- Replace “!30″ by “0″
c = 0<=0
Step 4 :
- Obviously 0 <= 0 is True Condition
- Replace Whole Expression by 1
c = 1
- Thus C = 1