Is the following an lvalue or rvalue

C

Chad

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
 
S

santosh

Chad said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top