Page 73 - Viva ICSE Computer Studies 8 : E-book
P. 73
• + : It is used to add two numbers, for example, num1 + num2.
• – : It is used to subtract two numbers, for example, num1 – num2.
• * : It is used to multiply two numbers, for example, num1 num2.
*
• / : It is used to divide two numbers, for example, num1/num2.
• % : It is used to calculate the remainder on dividing two numbers, for example,
num1%num2.
Increment and Decrement Operators
Increment operator ‘++’ is used to add 1 to the value of a variable while decrement operator
‘−−’ is used to subtract 1 from the value of a variable. For example, num ++ will add 1 to the
value of a variable num and num −− will subtract 1 from the value of a variable num.
Learn More
Increment and decrement operators ++ and −− can also be placed before the name of variables (such as
++ num and −− num), but they may give diff erent outputs depending upon the logic of a program. When
++ or −− is used before a variable name, it is called a pre-increment/pre-decrement operator. In this case,
the value of the variable is fi rst incremented or decremented and then used. While, in case ++ or −− is used
after a variable name, it is called a post-increment/post-decrement operator. Here, the value of the variable
is fi rst used and then increased or decreased.
Relational Operators
Relational operators are used to compare the values of two variables. A relational expression
returns either True or False. They include the following operators.
• > : It is used to fi nd whether the fi rst number is greater than the second, for example,
num1 > num2.
• < : It is used to fi nd whether the fi rst number is less than the second, for example,
num1 < num2.
• == : It is used to fi nd whether two numbers are equal, for example, num1 == num2.
• != : It is used to fi nd whether two numbers are not equal, for example, num1 != num2.
• >= : It is used to fi nd whether the fi rst number is greater than or equal to the second, for
example, num1 >= num2.
• <= : Used to fi nd whether the fi rst number is less than or equal to the second, for
example, num1 <= num2.
Logical Operators
Logical operators are used to fi nd whether one or both the conditions are true or false. They
include the following operators.
• && : It is used to fi nd whether both the conditions are true, for example, (8 > 3) &&
(6 > 2).
• !! : It is used to fi nd whether one of the two conditions is true, for example, (8 > 3) !!
(8 > 2).
• !! : It is used to fi nd whether the condition is false, for example, !num. !(8 = 3).
61