lvalue?

S

Shraddha

Sometimes we get an error of lvalue requred?What exactly is the lvalue?
And when this error occures?
 
W

Walter Roberson

Sometimes we get an error of lvalue requred?What exactly is the lvalue?
And when this error occures?

What did you come up with when you googled for lvalue ?
 
B

Ben Pfaff

Shraddha said:
Sometimes we get an error of lvalue requred?What exactly is the lvalue?

Informally speaking, an lvalue is an expression that can appear
on the left side of an assignment operator. Generally, an lvalue
is an expression that designates an object (a region of memory):
a variable, a dereferenced pointer, etc. In fact in C the
definition of an lvalue is different from what this informal idea
would suggest, but this is a reasonable place to start thinking
about them.
 
C

Chris Dollin

Ben said:
Informally speaking, an lvalue is an expression that can appear
on the left side of an assignment operator. Generally, an lvalue
is an expression that designates an object (a region of memory):
a variable, a dereferenced pointer, etc. In fact in C the
definition of an lvalue is different from what this informal idea
would suggest, but this is a reasonable place to start thinking
about them.

And there's plenty of stuff in the archives on this topic,
some of it more off-topic (but historically interesting)
than others.

[You get an "lvalue required" message when you are supposed
to have an lvalue but you didn't supply one; a typical
example would be assigning to an array or something++.]
 
T

Tor Rustad

Shraddha said:
Sometimes we get an error of lvalue requred?What exactly is the lvalue?
And when this error occures?

This is a FAQ, check Question 20.39b.

Let say i is a int, then consider the assignment

i = i + 1;

here the r.h.s "i" is an int value, while the identifier "i" on the l.h.s.
refers to something very different, namely a memory location.

Hence, l-value is the value of "i" on the l.h.s of the assignment, while
r-value refer to the value of the identifier on the r.h.s.
 

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,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top