Assigning a value to a constant syntax or semantic error?

Is the second line of code considered as a syntax error or a semantic error in C++?

 int a = 7;
 3 = a;

In standard C++ context-free grammar I found this statement syntactically valid.


It is not a syntax error, as the grammar can derive from assignment-expression (5.17) up to integer_literal

It is then a semantic error, as stated in 5.17:

All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand.

lvalue is a semantic concept, not a syntactic one.

链接地址: http://www.djcxy.com/p/29938.html

上一篇: while循环中的php性能问题

下一篇: 为常量语法或语义错误分配一个值?