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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With