Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a+++++b and a++ + ++b [duplicate]

Tags:

c

Possible Duplicate:
Why doesn't a+++++b work in C?
3 Plus between two variables in c

I tried searching for this but couldn't find any results.

A code with c=a+++++b fails to compile (gcc) whereas for c=a++ + ++b, it compiles successfully. c=a+++ ++b also works. c=a++ +++b fails.

Why is the whitespace making such a difference here? Or am i missing an important concept of C?

like image 265
nims Avatar asked Jun 29 '12 12:06

nims


People also ask

Is there any difference between a a B and A += B expressions?

No, the compiler doesn't differentiate between the two in output. The only difference is in parsing and possibly in lexical analysis (depending on expansion). You would generally use the shortcut form += .

What does a += b mean in Java?

For example, a += b is equivalent to a = a + b. '-=': This operator first subtracts the right operand from left operand and then assign the result to left operand. For example, a -= b is equivalent to a = a – b.


1 Answers

Since ++ is a token, the parser interprets a+++++b the same as a ++ ++ + b, which is not the same as a ++ + ++ b!

like image 69
Mr Lister Avatar answered Oct 31 '22 03:10

Mr Lister