Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RELATIONAL
- 9 is Big or Small
- We need 2 numbers to compare
- Maths : > < >= <= = (Not)=
- C lang : > < >= <= == != Relational Operator
- To Use Relational Operator we need 2 Number
- 5 > 3 YES -> ENGLISH WORD
- 1 > 4 NO
- Maths
- 5 > 3 TRUE -> Boolean
- 1 > 4 FALSE
- C- Lang
- 5 > 3 1
- 1 > 4 0
- Result of Relational Operator in C/C++ is always Either 0 (False)or 1 (True)
- a= 4>7; 0
- a= 10>5; 1
- a= 5>4; 1
- a= 5<2; 0 = Assingment
- a= 5<=3;0 == Comparison
- a= 9<=9; 1
- a= 7!=2; 1
- a= 9!=9; 0
- a= 4=4; Error Lvalue Error
- a= 5==4; 0
- a= 5>5; 0
- a= 5<5; 0
- a= 5>=5; 1
- a= 5!=5; 0
- a= 5>; Expression Syntax Error
- a = <= 8; Error ES
- a= -10>=8; 0
- a= 8 <= -25; 0
- a= 6.5 <= 6.8; 1
- a= 6.80 >= 6.8; 1
- a= 6.0==6; 1
- (==) Compares the value, not the data type
- a= 0.75 <= 0.7; 0
- a = 4>3>2; 0
- a= 4 > 3 + 9 < 20; 1
- a= 4 > 3 + 9 > 0; 0
- Priority
- 1. * / %
- 2. + -
- 3. > < >= <=
- 4. == !=
- 5. =
- =========================================
- int a = 5+6-2*5/3<=8+9>=7==1<=8+3*5>=6;
- Step1 5+6-10/3<=8+9>=7==1<=8+3*5>=6;
- Step2 5+6-3<=8+9>=7==1<=8+3*5>=6;
- Step3 5+6-3<=8+9>=7==1<=8+15>=6;
- Step4 11-3<=8+9>=7==1<=8+15>=6;
- Step5 8<=8+9>=7==1<=8+15>=6;
- Step6 8<=17>=7==1<=8+15>=6;
- Step7 8<=17>=7==1<=23>=6;
- Step8 1>=7==1<=23>=6;
- Step9 0==1<=23>=6;
- Step10 0==1>=6;
- Step11 0==0;
- Step12 1;
- ==========================================
- a = 5*2-12>=90/12<=31-45*2>=56<1>12<=3*12-13!=5;
- [5*2-12>=90/12<=31-45*2>=56<1>12<=3*12-13] !=5;
- [Result is 0 or 1] != 5; => 1
- Since != has Least Priority, it will done atlast.
- Relation operator in First Part [] will finally result either 0 or 1.
- [0 or 1] != 5; So final result is 1 anyways
- ============================================
- Ram is 4ft
- Ragu is 3ft -->Ram is Taller than Ragu (4>2)
- Ravi is 2ft -->Ragu is Taller than Ravi (3>2)--> Then Ram is also Taller than Ravi even without comparing (4>2)
- Ram>Ragu>Ravi (4>3>2) which is true
- But, a=4>3>2; Result in 0.
- Because Result of 1st operation is Compared with next value.
- We Must Compare Values with values not with result.
- ==============================================
- Student 1 & 2 in Movie
- Stu1 Says : I am Watching Movie
- Stu2 Says : I am Eating popcorn => This doesn't mean he is only eating popcorn
- It mean He is Watching Movie, Eating Popcorn. here (,) is wrong so,
- He is Watching Movie and Eating Popcorn. And Conjuction is used, which gives logical.
- SO, 10>4==4 wrong
- 10>4 and 4==4 Correct
- 4>3>2 Logical error a=4>3>2; => 0 Wrong
- a= 4>3>2;
- a= True>2; => Error False or True Cannot be compared with a value.
- 4>3 and 3>2 Logical Operator a=4>3 && 3>2; => 1 Correct
- Notes:
- => If we compile 2 or more relational operators directly then the result is unexpected. This is nothing but logical error.
- => To Overcome this, C people have introduced LOGICAL OPERATORS
- => The Purpose of Logical Operators is to combine two or more relation Statement and to get a compound Statement.
- ***************************************
- Logical Operator C,C++,Java Python
- 1. Logical And && and
- 2. Logical OR || or
- 3. Logical NOT ! not
- -------------------------------------------------------------------------------
- Logical Operator Table
- =====================
- Arg1 * Arg2 * Arg1 && Arg2 * Arg1 || Arg2 * !Arg1 * !Arg2
- Zero * Zero * 0 * 0 * 1 * 1
- Zero * Non-Zero * 0 * 1 * 1 * 0
- Non-Zero * Zero * 0 * 1 * 0 * 1
- Non-Zero * Non-Zero * 1 * 1 * 0 * 0
- ------------------------------------------------------------------------------------
- Username AND Password Login
- Correct Correct 1
- Correct Wrong 0
- Wrong Correct 0
- Wrong Wrong 0
- 8 && 45 => 1
- 0 && 45 => 0
- 8 && 0 => 0
- 0.2 && -45 => 1
- 1 && => ES Error
- 200 && 0.0 => 0
- Payment Portal => Debit Card OR UPI txn
- Completing any one payment method will be successfull.
- 10 || 0 => 1
- 0 || 0 => 0
- 0 || 8.32 => 1
- 0.0 || 0.6 => 1
- 0 || => ES Error
- Logical NOT (!)
- !(Non zero Except 0) => 0
- !(Zero) => 1
- Logical NOT Syntax >>>>>![Arg]<<<<<<
- !200 => 0
- !90.4=> 0
- !45 => 0
- !-98=> 0
- !0 => 1
- ! .0 =>1
- ! 0.0 => 1
- //////////////////////////////////////////////////////////
- Binary => && || == != * % / + - = > < >= <= Since It needs Both side for operation
- Unary => ! It needs only Ride side for operation
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Priority
- 1. ! R to L
- 2. * / % L to R
- 3. + - L to R
- 4. > < >= <= L to R
- 5. == != L to R
- 6. && L to R
- 7. || L to R
- 8. = R to L
- ----------------------------------------------------------------
- a= 2+3+4+5; 14 L to R
- a= !!!!!!!25; 0 R to L
- void main ()
- {
- int a;
- a=4;
- !!!!a; => Not Stored back in a
- printf("%d",a); 0 1 1 1 4
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement