# Is the following an lvalue or rvalue

Discussion in 'C Programming' started by Chad, Jul 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?

2. ### santoshGuest

> 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

On Jul 14, 5:43 am, santosh <> 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.