C++“左值”和“右值”

lvalue中的l指的是location,表示可以寻址。The "l" in value can be thought of as location.

rvalue中的r指的是read,表示可读。The "r" in value can be thought of as "read" value.

c++和++c的区别:

c++即是返回a的值,然后变量a加1,返回需要产生一个临时变量类似于:

{
    int temp = c;
    c = c + 1;
    return temp; //返回右值 
}

++c则为:

{
    c = c + 1;
    return &c;   //返回左值 
} 

显然,前增量不需要中间变量,效率更高。

posted @ 2012-06-04 10:56  waynewuzhenbo  阅读(189)  评论(0编辑  收藏  举报