Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

l-value , r-value in pointer C

Tags:

c

pointers

in C programming
i can't understand exactly what is l-value, r-value, and casting l-value to r-value, and casting r to l.

*x = *(x+1)
like image 619
manutd Avatar asked Dec 28 '22 22:12

manutd


1 Answers

An rvalue is just a value -- 17, or 3.14 or something on that order.

An lvalue is (simplifying a bit) something that refers to someplace in memory that can/does hold a value.

The most common lvalue is just a variable, so in something like x=10, x is an lvalue, and 10 is an rvalue. In fact, that's the origin of the names: an lvalue was (originally) anything that could appear on the Left side of an assignment, and an Rvalue was something that could appear on the right side of an assignment.

Converting an lvalue to an rvalue basically just means retrieving the value stored in the lvalue from wherever it's stored (usually memory). There isn't really any normal conversion from an rvalue to an lvalue though -- once you have something like 10, you can't convert back to a memory location. It's just 10 at that point, and the fact that there might be some variable with the value 10 (or more than one) doesn't mean you can convert the 10 back into the variable.

like image 143
Jerry Coffin Avatar answered Jan 12 '23 00:01

Jerry Coffin