开发者

How will C parse this sentence? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Close开发者_如何学Cd 11 years ago.

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜