What are unary + and - operators?
Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.
What are unary + and - operators?
Rating:
Operators that work on only one operand are called unary operators. The unary + operator is used to emphasize the sign of the operand, whereas the unary - operator is used to arithmetically negate the value of the operand. Both of these operators appear before the operand. For example,
+x
-x
Both of these operators promote the operand to the int type if the operand data type is byte, short, or char. Otherwise, the data type of the value obtained by these operators is the same as the type of the operand.
Rating:
Was this information helpful?
Other articles
- What is NumberFormatException?
- What is a block?
- What are the data type conversions available in Java?
- What is the StringBuffer class?
- What is the switch statement?