Thread: not an lvalue

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    2

    not an lvalue

    k obviously i am a noob, but i have observed the basic courtasies for posting. i searched for it in posts and did not find an answer, anyways...

    im trying to write a code to output (part of) the fib sequence, but i keep running into the same problem.
    Code:
    #include <iostream.h>
    int fib1[50]; 
    int a=0;  
    int b=1;
    int c=2;
    int main()
    {
     fib1[a]=1; //sets fib1[whatever # a is] to start out at 1
     fib1[b]=1;
     fib1[c]=2;
     for(int x=0;x<50;x++) //set for 50 repetitions
     {
      fib1[a]+fib1[b]=fib1[c];   //value in fib1[a]+value in fib1[b]=value in fib1[b]. but for somereason my compiler is saying its not an lvalue
      a++; //increments a
      b++;
      c++;
      cout<<fib1[a]<<", ";   //outputs #s
     }
    return 0;
    }
    i have tried putting the values from the array into int variables, but i had the same problem. same thing happended when i used pointers.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    l-value means left-value...

    The value on the left side of the = sign, is the "unknown".

    x = 5; // This is OK
    5 = X; // This is NOT OK

    fib1[c] = fib1[a] + fib1[b]; // Try This

    In C++ (and in programming in general), the equal-sign does not indicate an equation. It is the assignment operator. It assigns the value of the statement on the right to the variable on the left.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >> fib1[a]+fib1[b]=fib1[c];

    you have to put the thing being assigned on the left (lvalue)

    fib1[c] = fib1[a]+fib1[b];

    edit: d'oh, beaten by doug

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    2
    ahhh, i see, i should have know that. thanks so much for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lvalue rvalue discussion
    By George2 in forum C++ Programming
    Replies: 18
    Last Post: 03-04-2008, 05:48 AM
  2. A non-const reference may only be bound to an lvalue?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2007, 06:42 PM
  3. how to use reference for lvalue
    By jabka in forum C++ Programming
    Replies: 9
    Last Post: 04-22-2007, 02:08 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM