what does + sign after variable mean?

c, c++

Solution

I think DrYap has it right.

x = + + a + + + a + + + 5; 

is the same as:

x = + (+ a) + (+ (+ a)) + (+ (+ 5));

The key points here are:

1) c, c++ don't have + as a postfix operator, so we know we have to interpret it as a prefix

2) monadic + binds more tightly (is higher precedence) than dyadic +

Funny isn't it ? If these were - signs it wouldn't look so strange. Monadic +/- is just a leading sign, or to put it another way, "+x" is the same as "0+x".

Problem

what will be the output of following code `int x,a=3; x=+ +a+ + +a+ + +5; printf("%d %d",x,a);` ouput is: 11 3. I want to know how? and what does + sign after a means?

Original source

Related problems