我知道 C-Language Lvalue required 错误!当我们收到此错误时,我知道 2 到 3 种情况!Lvalue 表示:需要左侧值!
1)当我们将常量/文字分配给常量而不是变量时,我们得到了!
void main()
{
int a;
a = 2;
8 = 7;//Left side value (variable) required!
}
2) 使用前/后递增递减运算符!
void main()
{
int a = 2;
++a;
a++; //variable value is updating!
++2;
2++; //variable value has to be updatable! not a constant/literal value!
/*
Both pre & post unary operators workflow is Right --> Left.
Compiler treats this is also an assignment, So assignment always
happens to left side only!
That's why in these cases also compiler shows: Lvalue required error!
*/
}
3)棘手的声明!
void main()
{
int a = 2, b;
b = ++a++;
/*
++a++
evaluation is...
1st precedence is pre operator!
So,
++a --> 2 is substituted!
++a++; --> 2++ : variable value has to be updatable! not
a constant value! Lvalue required error!
*/
}
但是在这些情况下我们怎么会得到 Lvalue required 错误呢?求详细评价!
main()
{
int a=1, b;
//How come here we get Lvalue required error?
b = a+++++a;
b = a-----a;
//If i give spaces like below, compiler not getting confusion, no error!
b = a++ + ++a;
b = a–- – --a;
//here without spaces also i’m not getting any error!
b = a–-+–-a;
}
请有人对这些说法给出详细的运营商评价!
//without spaces!
b = a+++++a;
b = a-----a;
b = a--+--a;
//with spaces!
b = a++ + ++a;
b = a-- - --a;