“l-value required” error

前端 未结 11 2150
离开以前
离开以前 2020-12-10 00:06

When do we get \"l-value required\" error...while compiling C++ program???(i am using VC++ )

相关标签:
11条回答
  • 2020-12-10 00:38

    You are trying to use an invalid value for an l-value somewhere in your code. An l-value is an expression to which a value can be assigned.

    For example, you might have a statement like the following:

    10 = x;
    

    where you should instead have:

    x = 10;
    

    Although it is probably not this obvious in your case.

    0 讨论(0)
  • 2020-12-10 00:42

    This happen when you try manipulate the value of a constant may it be increments or decrements which is not allowed. `

    #define MAX 10
    void main(){
    int num;
    num  = ++MAX;
    cout<<num;
    }
    
    0 讨论(0)
  • 2020-12-10 00:45

    I had a similar issue and I found that the problem was I used a single '=' instead of a double '==' in an if statement

    lvalue error:

     if (n = 100) { code } // this is incorrect and comes back with the lvalue error
    

    correct:

    if (n == 100) { code } // this resolved my issue
    
    0 讨论(0)
  • 2020-12-10 00:46

    take for example

    *int a=10,b=20;

    int c=++(ab+1); above code will give error because inside the bracket you have a expression ont which you want to do increment operation which is not possible. So before doing doing that you have to store that value to some variable.so above code will error of "lvalue" required.

    0 讨论(0)
  • 2020-12-10 00:46

    Actually, this error occurs very often when you don't put a ";" and not to declare a variable that was probably prior to the variable that gives this error, not to declare throws this error since it cannot assign a value to a variable that was not declared ... smart boy!

    0 讨论(0)
  • 2020-12-10 00:47

    Typically one unaccustomed to C++ might code

    if ((x+1)=72) ...
    

    in place of

    if ((x+1)==72) ...
    

    the first means assign 72 to x+1 (clearly invalid) as opposed to testing for equality between 72 and (x+1)

    0 讨论(0)
提交回复
热议问题