If an lvalue appears in a situation in which the compiler expects an rvalue,
the compiler converts the lvalue to an rvalue.
An lvalue e of a type T can be converted to an rvalue if T is not a function or
array type. The type of e after conversion will be T.
Exceptions to this is:
Situation before conversion Resulting behavior
1) T is an incomplete type compile-time error
2) e refers to an uninitialized object undefined behavior
3) e refers to an object not of type T undefined behavior
问题1:
考虑以下程序,
int main()
{
char p[100]={0}; // p is lvalue
const int c=34; // c non modifiable lvalue
&p; &c; // no error fine beacuse & expects l-value
p++; // error lvalue required
return 0;
}
我的问题是,为什么在表达式中(p++)
++(postfix)
期望l-values
和数组是l-value
为什么会发生这个错误?
gcc 错误:需要左值作为增量操作数|
问题2:
请exception 3
用example
?