Velocity Reviews > Is the following an lvalue or rvalue

# Is the following an lvalue or rvalue

Guest
Posts: n/a

 07-14-2008
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?

santosh
Guest
Posts: n/a

 07-14-2008

> 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.

Guest
Posts: n/a

 07-14-2008
On Jul 14, 5:43*am, santosh <(E-Mail Removed)> 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.