Presentation is loading. Please wait.

Presentation is loading. Please wait.

.  A symbol to represent particular computer operation.  Consists of: o Assignment Operator o Arithmetic Operator o Relational Operator o Logical Operator.

Similar presentations


Presentation on theme: ".  A symbol to represent particular computer operation.  Consists of: o Assignment Operator o Arithmetic Operator o Relational Operator o Logical Operator."— Presentation transcript:

1

2  A symbol to represent particular computer operation.  Consists of: o Assignment Operator o Arithmetic Operator o Relational Operator o Logical Operator o Increment and Decrement Operator

3  In certain languages, for example in C++ language, equal (=) symbol is used as symbol in assignment operations.  This operator is used to change variable’s value.  Example: x = 5; So 5 are assigned to variable x.

4  Compound assignment operator is the operator that is combined with –, +, %, *, / and other operations.  Example: If a = 2, b = 4 a += b (means a = a + b) Result: a = 6

5 OperatorExampleEquivalent +=i += 8i = i + 8 -=f -= 8.0f = f - 8.0 *=i *= 8i = i * 8 /=i /= 8i = i / 8 %=i %= 8i = i % 8

6  Used to compute calculation operation done on a data in variables.  5 basic operator in programming language : SymbolOperator +Addition _Subtraction *Multiplication /Division %Modulus

7  Modulus (%)? o To get balance from two handling division. o i.e.: a) 5 % 3 is 2 1 3 5 3 2BALANCE IS 2!

8 b) 17 % 4 is 1 BALANCE IS 1! 4 17 16 1 4

9 OperatorPriority ( )Highest * / %Higher + -Lower

10 a) x = 5 + 2 * 4 – 1 _________________________________________ x = 5 + 2 * 4 – 1 x = 5 + 8 – 1 x = 13 - 1 x = 12 For same priority level, start from left side.

11 b) x = ( 5 + 2 ) * ( 4 - 1) x = ( 5 + 2 ) * ( 4 - 1) x = 7 * 3 x = 21 Bracket has a highest priority!!

12 Get the answer for this questions: a) 9 + 1 – 2 b) 2 * 5 + 2 / 1 c) 12 % 5 d) 4 + (7 - 3) * 3 e) ( 2 * 4 ) * 2 – ( 6 + 2 ) / 8

13  Is used to compare between 2 operands.  Comparison must be done on same data type o i.e. integer, character or string.  The result is either TRUE or FALSE. SymbolDescription >Greater than <Less than >=Greater or equal than <=Less or equal than ==Equal with !=Not equal with

14  Used to test some operation  Have 3 symbol: SymbolDescription &&AND ||OR !NOT

15  Based on the TRUTH TABLE PQP && QP || Q FALSE TRUEFALSETRUE FALSE TRUE

16 Given a = 3 and b = 5; a) x = (a > 0) && (b > 0) The x value is TRUE because 3 is greater than 0 AND 5 is greater than 0 as well. b) x = ( a < b ) && ( b == 0 ) The x value is FALSE. Although 3 is less than 5, but 5 is not equal with zero.

17 Find x value either TRUE or FALSE from the following equation: Given a = 2 and b = 4; a) x = ( a != 0 ) | | ( b != 0 ) b) x = ( a == b ) | | (b==0) c) x = ! ( a == b ) d) x = ! ( a < b)

18 a = ! ( 2 > 5) | | 6 + 3 >= 4 – 3; = ! (FALSE) | | (9 >= 1 ) = TRUE | | TRUE a = TRUE

19  Sometimes, we need to increment or decrement a single value in programming.  The value is as below:  Valid for variables only i.e. a++, b++, a--, b--, x++, y-- ……… and invalid for constant i.e. 5-- or 9++. SymbolOperator ++Add 1 --Minus 1

20  The ‘++’ and ‘- -’ can be put before or after variables.  i.e. we can write a++ or ++a, b-- or --b.

21 Given; a = 3 b = 5 i.a++  a value is 4 ii.a--  a value is 2 iii. b++  b value is 6 iv. b--  b value is 4

22 Given x = 8 y = 6 Find value for: 1. x++ 2. x-- 3. y++ 4. y-- 5. ++x 6. --y

23  All operators can be combined into one expression.  Notes below shows the priorities set for all operators: OPERATORS ()Highest priority !++ – – */ % +– >= = = != && || =Lowest priority

24


Download ppt ".  A symbol to represent particular computer operation.  Consists of: o Assignment Operator o Arithmetic Operator o Relational Operator o Logical Operator."

Similar presentations


Ads by Google