DifferenceEasy2 marks
Write a difference between unary and binary operator.
Topic: Unary and binary operators
Previous-year question practice database
Answer
Exam answer
The difference is shown in the table.
Explanation
The distinction is simply the NUMBER of operands, so say that plainly and give examples of each — the examples usually carry half the marks. Worth adding: Java also has exactly one ternary operator (? :), which acts on three operands. Mentioning it shows the full picture.
Comparison
| Unary operator | Binary operator |
|---|---|
| Acts on a single operand. | Acts on two operands. |
| Examples: ++, --, unary minus, ! | Examples: +, -, *, /, %, && |
More from Revision Tour I
The full form of JVM is:2026Which of the following occupies 2 bytes of storage?2026In a statement c = c + (x * d + e); which variable is an accumulator?2026Assertion (A): The result of the Java expression 3 + 7/2 is 6.
Reason (R): According to the hierarchy of operators in Java, addition is done first followed by division.2026Evaluate the Java expression:
x = a * b % (++c) + (++a) + (--b);
if a = 7, b = 8, c = 22026System.out.println('Z' + 32); will display:2025