Questions tagged «lvalue»


9
为什么A +++++ b不起作用?
int main () { int a = 5,b = 2; printf("%d",a+++++b); return 0; } 此代码给出以下错误: 错误:需要左值作为增量操作数 但是,如果我在a++ +和之间放置空格++b,则效果很好。 int main () { int a = 5,b = 2; printf("%d",a++ + ++b); return 0; } 该错误在第一个示例中意味着什么?
88 c  lvalue 

3
C ++:返回值是L值吗?
考虑以下代码: struct foo { int a; }; foo q() { foo f; f.a =4; return f;} int main() { foo i; i.a = 5; q() = i; } 没有编译器抱怨它,即使是Clang。为什么q() = ...行是正确的?

3
为什么(++ i)++有效,“ ++ i ++”无效?
让我们考虑以下代码: int main() { int i = 2; int b = ++i++; return 3; } 编译时出现以下错误: <source>: In function 'int main()': <source>:3:16: error: lvalue required as increment operand 3 | int b = ++i++; | ^~ 这对我来说听起来很公平。后缀递增的优先级高于前缀递增的优先级,因此代码被解析为int b = ++(i++);,i是一个右值。因此,错误。 现在,让我们考虑带有括号的此变体,以覆盖默认优先级: int main() { int i = 2; int b …

2
为什么这里的枚举变量是右值?
例: typedef enum Color { RED, GREEN, BLUE } Color; void func(unsigned int& num) { num++; } int main() { Color clr = RED; func(clr); return 0; } 编译时出现以下错误: <source>: In function 'int main()': <source>:16:9: error: cannot bind non-const lvalue reference of type 'unsigned int&' to an rvalue of type …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.