What does the term "Urnary operator" mean?

Operators that affect a single variable. So the use of – to make a negative number is a urnary operator.

Operator Use Description
++ x++ x + 1
x– x – 1

Note that with unary operators you can have post-increment and pre-increment. x++ is post-increment; the number is incremented by 1 after everything else in the statement has occurred. If you wrote it as ++x (a pre-increment) x would be increased by 1 before everything else.

So, we have:

number = 10;
newNumber = ++number;

In this case both number and newNumber would be 11. This is because the statement increases number by 1, making it 11, and then makes newNumber equal to it. If you did:

number = 10;
newNumber = number++;

Only number would be equal to 11, because newNumber is set to the value of number first, which is 10, before it is incremented by 1.

Leave a Reply

Thank you for choosing to leave a comment. Comments may be moderated.