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

Answer
Prefix IncrementPostfix 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 DecrementPostfix 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 OperatorsBinary Operators
It operates on a single operandIt operates on two operands
Increment (++) and Decrement (--) operators are examples of Unary Arithmetic OperatorsMultiplication (*) and Division (/) are examples of Binary Arithmetic Operators

d. Increment and Decrement Operator

Increment OperatorDecrement 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 operatorIt is the Modulus operator
Returns the quotient of division operationReturns 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 operationExample: int b = 5 % 2; Here b will get the value of 1 which is the remainder of this division operation