Lvalue Required......Why?

Discussion in 'C Programming' started by Sai Krishna M, Nov 20, 2003.

  1. Lvalue Required......Why?


    Hello all,

    the following code is not compiling in Turbo C and the error
    is "Lvalue Required" .

    main()
    {

    int i;

    i++ = 10;

    }


    As I understand, we're trying to assingn 10 to i first, gettin 11 and then
    trying to increment 11, which doesn't have a memory loc, being a Number.

    But, why also 11 should ha a location, right?



    plz clarify.
     
    Sai Krishna M, Nov 20, 2003
    #1
    1. Advertising

  2. Sai Krishna M

    Chris Dollin Guest

    Sai Krishna M wrote:

    > Lvalue Required......Why?


    It's the Law.

    >
    > the following code is not compiling in Turbo C and the error
    > is "Lvalue Required" .
    >
    > main()
    > {
    > int i;
    > i++ = 10;


    The result of i++ is a value, not an assignable object. You can't assign
    to values: `10 = 17;` is not legal.

    [Note also that i++ is Bad anyway, since i is not initialised.]

    > }
    >
    > As I understand, we're trying to assingn 10 to i first, gettin 11 and then
    > trying to increment 11, which doesn't have a memory loc, being a Number.


    No - we're "trying" to assign 10 to the result of i++. The i++ must be
    evaluated before the assignment happens. [Well, it would be "must" if
    it were legal, if it were legal and sane.]

    > But, why also 11 should ha a location, right?


    Wrong.

    --
    Chris "electric hedgehog" Dollin
    C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html
    C welcome: http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
     
    Chris Dollin, Nov 20, 2003
    #2
    1. Advertising

  3. Sai Krishna M

    John Bode Guest

    "Sai Krishna M" <> wrote in message news:<bpi1g0$m2$>...
    > Lvalue Required......Why?
    >
    >
    > Hello all,
    >
    > the following code is not compiling in Turbo C and the error
    > is "Lvalue Required" .
    >
    > main()
    > {
    >
    > int i;
    >
    > i++ = 10;


    The result of the autoincrement operator on an int object is a value,
    and you cannot assign to a value (what you have written is basically
    the equivalent of writing 0 = 10, except there's no guarantee that i
    was initialized to 0). i++ reads as "return the current value of i,
    then at some point before the next sequence point, increment i by 1."

    >
    > }
    >
    >
    > As I understand, we're trying to assingn 10 to i first, gettin 11 and then
    > trying to increment 11, which doesn't have a memory loc, being a Number.
    >
    > But, why also 11 should ha a location, right?


    Not necessarily. If I have the lines

    i = 10;
    i++;

    the line "i++" evaluates to 10, which is then discarded.

    >
    >
    >
    > plz clarify.
     
    John Bode, Nov 20, 2003
    #3
  4. Groovy hepcat Sai Krishna M was jivin' on Thu, 20 Nov 2003 14:58:27
    +0530 in comp.lang.c.
    Lvalue Required......Why?'s a cool scene! Dig it!

    > the following code is not compiling in Turbo C and the error
    >is "Lvalue Required" .
    >
    >i++ = 10;
    >
    >As I understand, we're trying to assingn 10 to i first, gettin 11 and then
    >trying to increment 11, which doesn't have a memory loc, being a Number.
    >
    >But, why also 11 should ha a location, right?


    Wrong!

    >plz clarify.


    Go and get FAQed. You should have read the FAQ before posting. Go
    and do so right now. You'll find the FAQ at the following URL:

    http://www.eskimo.com/~scs/C-faq/top.html

    --

    Dig the even newer still, yet more improved, sig!

    http://alphalink.com.au/~phaywood/
    "Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
    I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
     
    Peter Shaggy Haywood, Nov 23, 2003
    #4
  5. Sai Krishna M

    Peace Guest

    "Sai Krishna M" <> wrote in message news:<bpi1g0$m2$>...
    > Lvalue Required......Why?


    Read the FAQ it's the LAW.
    >
    >
    > Hello all,
    >
    > the following code is not compiling in Turbo C and the error
    > is "Lvalue Required" .
    >
    > main()
    > {
    >
    > int i;
    >
    > i++ = 10;
    >
    > }
    >
    >

    What are you trying to achieve here? i++ is evaluates to a value, it
    is not a variable to which you can assign a value.Why can't you write
    your peice of code like this:
    void main ()
    {
    int i=9;
    i++;
    }
    > As I understand, we're trying to assingn 10 to i first, gettin 11 and then
    > trying to increment 11, which doesn't have a memory loc, being a Number.
    >

    Wrong. Go read some good C books.
    > But, why also 11 should ha a location, right?
    >

    Wrong again.
    >
    >
    > plz clarify.
     
    Peace, Nov 24, 2003
    #5
  6. Peace <> spoke thus:

    Speaking of wrong...

    > void main ()


    ....is *very* wrong. main() returns an int.

    > Wrong. Go read some good C books.


    A valid suggestion for both of you.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Nov 24, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,996
    Smokey Grindel
    Dec 2, 2006
  2. Kavya
    Replies:
    9
    Views:
    513
    Dik T. Winter
    Oct 28, 2006
  3. Replies:
    11
    Views:
    697
    James Kuyper
    Sep 22, 2008
  4. Pavel
    Replies:
    13
    Views:
    1,092
    Pavel
    Jul 5, 2011
  5. Julian Mehnle
    Replies:
    0
    Views:
    239
    Julian Mehnle
    Jul 17, 2003
Loading...

Share This Page