A Quick Question Regarding '+' Prefix

closed account (zb0S216C)
I've ran into this today: ( 40 + +2 ). Does the +2 denote a positive integer just as -2 denotes a negative integer?

Wazzak
closed account (1vRz3TCk)
It is the Unary Plus Operator: +

I'm not quite sure why you would need it there, but it returns the value of its operand; for an integral type, an int is returned.

See Integral Promotions.
Last edited on
closed account (zb0S216C)
Thanks for the reply CodeMonkey. So basically, I could omit the prefixing + and it wouldn't make a difference? Are there any cases which require the prefixed +?

Wazzak
I've personally never found any use for the unary + operator.

And yeah, you could omit it there and it wouldn't make any difference.
closed account (zb0S216C)
Simple enough. Thanks to you both :)

Wazzak
I suppose you could overload it with something so it does something useful, but that would just make your code less intuitive to read.
Topic archived. No new replies allowed.