Advertisement
Mukezh

Session 5 Relational Operator

Dec 8th, 2020 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. RELATIONAL
  2.  
  3. 9 is Big or Small
  4. We need 2 numbers to compare
  5.  
  6. Maths : > < >= <= = (Not)=
  7. C lang : > < >= <= == != Relational Operator
  8. To Use Relational Operator we need 2 Number
  9.  
  10. 5 > 3 YES -> ENGLISH WORD
  11. 1 > 4 NO
  12. Maths
  13. 5 > 3 TRUE -> Boolean
  14. 1 > 4 FALSE
  15. C- Lang
  16. 5 > 3 1
  17. 1 > 4 0
  18. Result of Relational Operator in C/C++ is always Either 0 (False)or 1 (True)
  19.  
  20. a= 4>7; 0
  21. a= 10>5; 1
  22. a= 5>4; 1
  23. a= 5<2; 0 = Assingment
  24. a= 5<=3;0 == Comparison
  25. a= 9<=9; 1
  26. a= 7!=2; 1
  27. a= 9!=9; 0
  28. a= 4=4; Error Lvalue Error
  29. a= 5==4; 0
  30. a= 5>5; 0
  31. a= 5<5; 0
  32. a= 5>=5; 1
  33. a= 5!=5; 0
  34. a= 5>; Expression Syntax Error
  35. a = <= 8; Error ES
  36. a= -10>=8; 0
  37. a= 8 <= -25; 0
  38. a= 6.5 <= 6.8; 1
  39. a= 6.80 >= 6.8; 1
  40. a= 6.0==6; 1
  41. (==) Compares the value, not the data type
  42. a= 0.75 <= 0.7; 0
  43. a = 4>3>2; 0
  44. a= 4 > 3 + 9 < 20; 1
  45. a= 4 > 3 + 9 > 0; 0
  46. Priority
  47. 1. * / %
  48. 2. + -
  49. 3. > < >= <=
  50. 4. == !=
  51. 5. =
  52. =========================================
  53. int a = 5+6-2*5/3<=8+9>=7==1<=8+3*5>=6;
  54. Step1 5+6-10/3<=8+9>=7==1<=8+3*5>=6;
  55. Step2 5+6-3<=8+9>=7==1<=8+3*5>=6;
  56. Step3 5+6-3<=8+9>=7==1<=8+15>=6;
  57. Step4 11-3<=8+9>=7==1<=8+15>=6;
  58. Step5 8<=8+9>=7==1<=8+15>=6;
  59. Step6 8<=17>=7==1<=8+15>=6;
  60. Step7 8<=17>=7==1<=23>=6;
  61. Step8 1>=7==1<=23>=6;
  62. Step9 0==1<=23>=6;
  63. Step10 0==1>=6;
  64. Step11 0==0;
  65. Step12 1;
  66. ==========================================
  67. a = 5*2-12>=90/12<=31-45*2>=56<1>12<=3*12-13!=5;
  68. [5*2-12>=90/12<=31-45*2>=56<1>12<=3*12-13] !=5;
  69. [Result is 0 or 1] != 5; => 1
  70.  
  71. Since != has Least Priority, it will done atlast.
  72. Relation operator in First Part [] will finally result either 0 or 1.
  73. [0 or 1] != 5; So final result is 1 anyways
  74. ============================================
  75. Ram is 4ft
  76. Ragu is 3ft -->Ram is Taller than Ragu (4>2)
  77. Ravi is 2ft -->Ragu is Taller than Ravi (3>2)--> Then Ram is also Taller than Ravi even without comparing (4>2)
  78. Ram>Ragu>Ravi (4>3>2) which is true
  79. But, a=4>3>2; Result in 0.
  80. Because Result of 1st operation is Compared with next value.
  81. We Must Compare Values with values not with result.
  82. ==============================================
  83. Student 1 & 2 in Movie
  84. Stu1 Says : I am Watching Movie
  85. Stu2 Says : I am Eating popcorn => This doesn't mean he is only eating popcorn
  86. It mean He is Watching Movie, Eating Popcorn. here (,) is wrong so,
  87. He is Watching Movie and Eating Popcorn. And Conjuction is used, which gives logical.
  88. SO, 10>4==4 wrong
  89. 10>4 and 4==4 Correct
  90. 4>3>2 Logical error a=4>3>2; => 0 Wrong
  91. a= 4>3>2;
  92. a= True>2; => Error False or True Cannot be compared with a value.
  93. 4>3 and 3>2 Logical Operator a=4>3 && 3>2; => 1 Correct
  94.  
  95. Notes:
  96. => If we compile 2 or more relational operators directly then the result is unexpected. This is nothing but logical error.
  97. => To Overcome this, C people have introduced LOGICAL OPERATORS
  98. => The Purpose of Logical Operators is to combine two or more relation Statement and to get a compound Statement.
  99.  
  100. ***************************************
  101. Logical Operator C,C++,Java Python
  102. 1. Logical And && and
  103. 2. Logical OR || or
  104. 3. Logical NOT ! not
  105. -------------------------------------------------------------------------------
  106. Logical Operator Table
  107. =====================
  108. Arg1 * Arg2 * Arg1 && Arg2 * Arg1 || Arg2 * !Arg1 * !Arg2
  109. Zero * Zero * 0 * 0 * 1 * 1
  110. Zero * Non-Zero * 0 * 1 * 1 * 0
  111. Non-Zero * Zero * 0 * 1 * 0 * 1
  112. Non-Zero * Non-Zero * 1 * 1 * 0 * 0
  113. ------------------------------------------------------------------------------------
  114. Username AND Password Login
  115. Correct Correct 1
  116. Correct Wrong 0
  117. Wrong Correct 0
  118. Wrong Wrong 0
  119.  
  120. 8 && 45 => 1
  121. 0 && 45 => 0
  122. 8 && 0 => 0
  123. 0.2 && -45 => 1
  124. 1 && => ES Error
  125. 200 && 0.0 => 0
  126.  
  127. Payment Portal => Debit Card OR UPI txn
  128. Completing any one payment method will be successfull.
  129.  
  130. 10 || 0 => 1
  131. 0 || 0 => 0
  132. 0 || 8.32 => 1
  133. 0.0 || 0.6 => 1
  134. 0 || => ES Error
  135.  
  136. Logical NOT (!)
  137. !(Non zero Except 0) => 0
  138. !(Zero) => 1
  139. Logical NOT Syntax >>>>>![Arg]<<<<<<
  140. !200 => 0
  141. !90.4=> 0
  142. !45 => 0
  143. !-98=> 0
  144. !0 => 1
  145. ! .0 =>1
  146. ! 0.0 => 1
  147. //////////////////////////////////////////////////////////
  148. Binary => && || == != * % / + - = > < >= <= Since It needs Both side for operation
  149.  
  150. Unary => ! It needs only Ride side for operation
  151. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  152. Priority
  153. 1. ! R to L
  154. 2. * / % L to R
  155. 3. + - L to R
  156. 4. > < >= <= L to R
  157. 5. == != L to R
  158. 6. && L to R
  159. 7. || L to R
  160. 8. = R to L
  161. ----------------------------------------------------------------
  162. a= 2+3+4+5; 14 L to R
  163. a= !!!!!!!25; 0 R to L
  164.  
  165. void main ()
  166. {
  167. int a;
  168. a=4;
  169. !!!!a; => Not Stored back in a
  170. printf("%d",a); 0 1 1 1 4
  171. }
  172.  
  173.  
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement