Win a copy of Design for the Mind this week in the Design forum!

# unary operator

geetha nagarajan
Ranch Hand
Posts: 94
Q:An unary operator operates on a single value
1.True
2.False
The answer is given as False,bcos + and -,can take two values.
Since,+ and - can be used both as unary and binary operator,what would be the best possible explanation in this context?

Jose Botella
Ranch Hand
Posts: 2120
The same symbols are used for unary operators:
+variable
-variable
var1 + var2
var1 - var2
I disagree with the answer. Because additive operators are not unary ones. Though they share the same symbols.

geetha nagarajan
Ranch Hand
Posts: 94
When '+' or '-' is used as a unary operator,it acts only on a single value,right.
There was another question about operands :
Q:All operands r evaluated left to right.
1.true
2.false.
The answer is given as true.Will the precedence and associativity rules not apply?
Pl.clarify.

Jose Botella
Ranch Hand
Posts: 2120
After the operands are evaluated, the operations are performed based on the precedence of the operators (and parentheses). Associativity plays a rol when considering operators with the same precedence.