What does the + sign mean after a variable?

what will be the output of the 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 the + sign mean after the means?

+5
source share
5 answers

I think DrYap is correct.

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

matches with:

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

The key points here are:

1) c, C ++ do not have + as a postfix operator, so we know that we should interpret it as a prefix

2) monadic + binds more rigidly (higher priority) than dyadic +

It's funny, isn't it? If it were - signs, it would not look so strange. Monadic +/- is simply a leading character, or, to put it another way, "+ x" matches "0 + x".

+18
source

+ , + . , , :

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

+ s , , :

x = a + a + 5;

a , , ++ + . + ++ - .

+13

:

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

.. x = a + a + 5. 11. , + - , ? + . +, I.e. "+5" "5", "+ a" "a", "+ + a" "+ (+ a)", "a". x = + + + 3 + + + + 3 + + + + 5. x = - + + - 3 + - + - 3 - - + 5;.

+3

Since the operators are +never next to each other, but are always separated by a space, the operator is x=+ +a+ + +a+ + +5;actually read as

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

so that ultimately the final equation becomes x=a+a+5;and therefore the result.

+3
source

x = + + a + + + a + + +5: This is equivalent

x = x = + + a + + + a + + +5 or we can write it as x = + (+ a) + (+ (+ a)) + (+ (+ 5)) and + denote only signs, which will be finally evaluated as x = a + a + 5.

0
source

All Articles