Is the following an lvalue or rvalue

Discussion in 'C Programming' started by Chad, Jul 14, 2008.

  1. Chad

    Chad Guest

    I have the folllowing

    #include <stdio.h>

    int main(void)
    {
    int x = 1, y = 2;
    int *ip;

    ip = &x;

    y = *ip;

    printf("The value is: %d\n", y);

    return 0;
    }


    Would *ip in y = *ip be a lvalue or rvalue in this case? Here is my
    main source of confusion. I thought that applying the indirection
    operator to ip would yield a lvalue and thus something like *ip could
    only appear on the left hand side. However,since *ip is on the right
    hand side in this case, would *ip be a lvalue or rvalue?

    Chad
     
    Chad, Jul 14, 2008
    #1
    1. Advertising

  2. Chad

    santosh Guest

    Chad wrote:

    > I have the folllowing
    >
    > #include <stdio.h>
    >
    > int main(void)
    > {
    > int x = 1, y = 2;
    > int *ip;
    >
    > ip = &x;
    > y = *ip;
    >
    > printf("The value is: %d\n", y);
    >
    > return 0;
    > }
    >
    >
    > Would *ip in y = *ip be a lvalue or rvalue in this case? Here is my
    > main source of confusion. I thought that applying the indirection
    > operator to ip would yield a lvalue and thus something like *ip could
    > only appear on the left hand side. However,since *ip is on the right
    > hand side in this case, would *ip be a lvalue or rvalue?


    It's a lvalue used in a rvalue context.
     
    santosh, Jul 14, 2008
    #2
    1. Advertising

  3. Chad

    Chad Guest

    On Jul 14, 5:43 am, santosh <> wrote:
    > Chad wrote:
    > > I have the folllowing

    >
    > > #include <stdio.h>

    >
    > > int main(void)
    > > {
    > >   int x = 1, y = 2;
    > >   int *ip;

    >
    > >   ip = &x;
    > >   y = *ip;

    >
    > >   printf("The value is: %d\n", y);

    >
    > >   return 0;
    > > }

    >
    > > Would *ip in y = *ip be a lvalue or rvalue in this case? Here is my
    > > main source of confusion. I thought that applying the indirection
    > > operator to ip would yield a lvalue and thus something like *ip could
    > > only appear on the left hand side. However,since *ip is on the right
    > > hand side in this case, would *ip be a lvalue or rvalue?

    >
    > It's a lvalue used in a rvalue context.- Hide quoted text -
    >
    > - Show quoted text -


    Okay.
     
    Chad, Jul 14, 2008
    #3
    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. Chris Mantoulidis

    ++x returns lvalue but x++ return rvalue

    Chris Mantoulidis, Dec 28, 2003, in forum: C++
    Replies:
    4
    Views:
    511
    Chris Mantoulidis
    Dec 29, 2003
  2. Gonzalo Aguirre

    rvalue / lvalue operator[]

    Gonzalo Aguirre, Jan 2, 2004, in forum: C++
    Replies:
    4
    Views:
    464
    Ron Natalie
    Jan 2, 2004
  3. Denis Remezov

    lvalue rvalue

    Denis Remezov, Jul 16, 2004, in forum: C++
    Replies:
    12
    Views:
    895
  4. Kavya
    Replies:
    9
    Views:
    541
    Dik T. Winter
    Oct 28, 2006
  5. Juha Nieminen
    Replies:
    13
    Views:
    651
    Edek Pienkowski
    Aug 29, 2012
Loading...

Share This Page