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?
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 += .
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.
Since ++
is a token, the parser interprets a+++++b
the same as a ++ ++ + b
, which is not the same as a ++ + ++ b
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With