Sobes.tech
Junior — Middle

Can you explain what a unary operator is and how it differs from other operators?

sobes.tech AI

Answer from AI

A unary operator is an operator that acts on only one operand. For example, in Java language, unary operators include:

  • ++ (increment) and -- (decrement), e.g., i++
  • unary minus -, e.g., -a
  • logical negation !, e.g., !flag

The difference between unary and binary operators is that binary operators require two operands (e.g., a + b), while unary operators only need one. Unary operators are applied directly to a single value or variable and modify or return a result based on that single operand.

Can you explain what a unary operator is and how it… - sobes.tech