A Quick Question Regarding '+' Prefix

Sep 19, 2011 at 3:19pm
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
Sep 19, 2011 at 3:28pm
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 Sep 19, 2011 at 3:38pm
Sep 19, 2011 at 4:12pm
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
Sep 19, 2011 at 4:30pm
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.
Sep 19, 2011 at 4:46pm
closed account (zb0S216C)
Simple enough. Thanks to you both :)

Wazzak
Sep 19, 2011 at 4:53pm
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.