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 06:20 PM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,951
    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.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  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
    23,820
    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".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 12:45 PM
  2. error: lvalue required as left operand of assignment
    By owjian1987 in forum C Programming
    Replies: 5
    Last Post: 02-11-2011, 11:34 AM
  3. Replies: 3
    Last Post: 06-01-2010, 06:22 AM
  4. lvalue required as left operand of assignment
    By joeman in forum C++ Programming
    Replies: 11
    Last Post: 03-27-2010, 12:36 AM
  5. lvalue required as left operand of assignment (??)
    By oospill in forum C Programming
    Replies: 3
    Last Post: 11-03-2009, 10:02 PM

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