开发者

l-value , r-value in pointer C

in C programming

i can't unders开发者_JAVA技巧tand 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.


The C standard recognizes the original terms placed for left and right as in L = R; however, it says to think of lvalue as locator value, which roughly means you can get the address of an object and therefore that object has a location.

The r-value is said to as a The Value of an expression which may be literals , int ,float any value.

So in you example left hand side is a Location value in which the right hand expression value is going to be set.


How about the explanation here? http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Flvalue.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜