When there is a space between + +
, what is meaning of expression "+ + a
". How is this expression evaluated?
int main()
{
int a = 3;
printf("%d %d", + +a, a);
}
and also how is a+++a
evaluated?
Is it undefined or unspecified or implementation defined?
1. : the act of making your thoughts, feelings, etc., known by speech, writing, or some other method : the act of expressing something. [noncount] freedom of expression [=freedom to say and show what you feel and believe] Dance is a form of artistic/creative expression.
It is a no-op — twice because + a
is a no-op and it is repeated.
a+++a
is unambiguously parsed as a++ + a
, but leads to undefined behaviour when executed.
Note that if the code set a = -3;
, the value printed would still be -3
, twice.
When there is a space in the middle in the ++
operator, then you are just applying the unary plus operator twice.
About the expression a+++a
,
the C specification says that when there is such an ambiguity, munch as much as possible (the
"greedy lexer" or "maximal munch" rule). So a+++a
is evaluated as a++ + a
According to that rule, an expression like, z = y+++++x;
will be parsed as z = y++ ++ +x;
, which is invalid (the result of a post-increment is not itself incrementable).
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