How to change a positive number to a negative and vice versa?

I think there should be a function for both. I think factories will make negative positives.

But not sure of the other?

+5
source share
2 answers

num *= -1 will change the sign from positive to negative and vice versa.

+11
source

I would rather write like this:

num = -num;

This does not require multiplication, just by changing the sign.

+11
source

All Articles