What does the compiler do here: int a = b * (c * d * + e)?

Michael picture Michael · May 20, 2015 · Viewed 8.4k times · Source

I had a strange bug in my program, and after a few hours of debugging, I found the following very stupid line:

int a = b * (c * d *  + e)

If you don't see it: Between d and e I wrote * +, where just a +was intended.

Why does this compile and what does it actually mean?

Answer

Brian Bi picture Brian Bi · May 20, 2015

The + is interpreted as an unary plus operator. It simply returns the promoted value of its operand.