ICSE Class 10 Computer Applications
Question 10 of 26
Operators in Java — Question 10
Back to all questions 10
Question Question 10
Distinguish between the following:
a. Prefix and Postfix Increment
| Prefix Increment | Postfix Increment |
|---|---|
| It works on the principle of first increment, then use. | It works on the principle of first use, then increment. |
| It (++) is written before the operand. | It (++) is written after the operand. |
Example:int a = 99;int b = ++a;After the execution of these two statements, both a and b will have the value of 100. | Example:int a = 99;int b = a++;After the execution of these two statements, a will have the value of 100 and b will have the value of 99. |
b. Prefix and Postfix Decrement
| Prefix Decrement | Postfix Decrement |
|---|---|
| It works on the principle of first decrement, then use. | It works on the principle of first use, then decrement. |
| It (--) is written before the operand. | It (--) is written after the operand. |
Example:int a = 100;int b = --a;After the execution of these two statements, both a and b will have the value of 99. | Example:int a = 100;int b = a--;After the execution of these two statements, a will have the value of 99 and b will have the value of 100. |
c. Unary and Binary Operators
| Unary Operators | Binary Operators |
|---|---|
| It operates on a single operand | It operates on two operands |
| Increment (++) and Decrement (--) operators are examples of Unary Arithmetic Operators | Multiplication (*) and Division (/) are examples of Binary Arithmetic Operators |
d. Increment and Decrement Operator
| Increment Operator | Decrement Operator |
|---|---|
| Increment operators increment the value of their operand by 1. | Decrement operators decrement the value of their operand by 1. |
| Increment operators are represented by ++ symbol. | Decrement operators are represented by -- symbol. |
e. / and % operator
| / | % |
|---|---|
| It is the Division operator | It is the Modulus operator |
| Returns the quotient of division operation | Returns the remainder of division operation |
| Example: int a = 5 / 2; Here a will get the value of 2 which is the quotient of this division operation | Example: int b = 5 % 2; Here b will get the value of 1 which is the remainder of this division operation |