lvalue required as left operand of assignment

This is a discussion on lvalue required as left operand of assignment within the C Programming forums, part of the General Programming Boards category; I keep getting this error when I try to compile a program and cant see how to solve it. From ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    2

    lvalue required as left operand of assignment

    I keep getting this error when I try to compile a program and cant see how to solve it. From looking at similar problems posted here it is normally to do with using the assignment = , rather than testing if equal to == . However, in this case I am trying to assign a value to a variable (to be specific the memory address of a matrix entry).

    I am getting the error for lines 4,7 and 10 in this segmant of code.

    Code:
    int type1(int left, int L){
        int k, M, X, matrix[L][L];
        for(k=1; (k>(left-M)); k++){
            &(matrix[left][k])=0;
        }
        for(k; k<(left-X); k++){
            &matrix[left][k]=1/(X-M+1);
        }
        for(k; k<L; k++){
            &matrix[left][k]=0;
        }
    }
    I am stumped, can someone please explain what is wrong.
    Last edited by Thai guy; 06-03-2012 at 07:20 PM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,773
    The message means, The value on the left is NOT legal to be assigned a new value.

    It is likely the same cause as when you try to assign a new address to an array.
    That is also not a legal/permitted thing to be done.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    The address of operator does not make sense on the right side of the assignment operator. It's used to give up the address for element [left][k] so that it can be assigned to a pointer. You can assign the value directly to the array, as dereference is done for you.

  4. #4
    Registered User
    Join Date
    Jun 2012
    Posts
    2
    Quote Originally Posted by Subsonics View Post
    The address of operator does not make sense on the right side of the assignment operator. It's used to give up the address for element [left][k] so that it can be assigned to a pointer. You can assign the value directly to the array, as dereference is done for you.
    That makes sense, thankyou for the speedy replies.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Quote Originally Posted by Subsonics
    The address of operator does not make sense on the right side of the assignment operator.
    Thai guy: you might have understood it anyway, but that sentence has a typo error, i.e., "right side" should be "left side", hence the "l" in "lvalue".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lvalue required as left operand of assignment
    By ModeSix in forum C Programming
    Replies: 6
    Last Post: 04-14-2011, 01:45 PM
  2. error: lvalue required as left operand of assignment
    By owjian1987 in forum C Programming
    Replies: 5
    Last Post: 02-11-2011, 12:34 PM
  3. Replies: 3
    Last Post: 06-01-2010, 07:22 AM
  4. lvalue required as left operand of assignment
    By joeman in forum C++ Programming
    Replies: 11
    Last Post: 03-27-2010, 01:36 AM
  5. lvalue required as left operand of assignment (??)
    By oospill in forum C Programming
    Replies: 3
    Last Post: 11-03-2009, 11:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21