How will C parse this sentence? [closed]
According to the official description of the C language, what number will be returned?
int a, b;
a = 5;
b = a+++++a;
return b;
It is parsed as:
b = (a++)++ + a;
This is an invalid expression. The increment operator can't be applied twice as (a++)
isn't an lvalue.
The tokenizer isn't context-aware and will match the longest token possible, so it is not parsed as the syntactically valid a++ + ++a
. (That still would be invalid code, though, since it modifies a
twice without a sequence point which invokes undefined behavior.)
精彩评论