易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++中左值和右值的差别

我们常说的左值lvalue和右值rvalue并不简单地意味着左右区别,它的原始定义如下:
Definition:
C and C++ have the notion of lvalues and rvalues associated with
variables and constants. The rvalue is the data value of the variable,
that is, what information it contains. The "r" in rvalue can be thought of as "read"
value
. A variable also has an associated lvalue. The "l" in lvalue can be though of as location
,
meaning that a variable has a location that data or information can be
put into. This is contrasted with a constant. A constant has some data
value, that is an rvalue. But, it cannot be written to. It does not
have an lvalue.
Another view of these terms is that objects with an rvalue, namely a
variable or a constant can appear on the right hand side of a
statement. They have some data value that can be manipulated. Only
objects with an lvalue, such as variable, can appear on the left hand
side of a statement. An object must be addressable to store a value.
Here are two examples.
int x;
x = 5; // This is fine, 5 is an rvalue, x can be an lvalue.
5 = x; // This is illegal. A literal constant such as 5 is not
      // addressable. It cannot be a lvalue.

引文中说: "The "r" in rvalue can be thought of as "read" value."
就是你可以把 "r" 理解为 "read". 并没有说就是 "read" 的意思!
lvalue, rvalue称为"左值", "右值" 并没有违背原意. 因为,
到目前为止, 所有计算机语言都是将被赋值量置于赋值号左端的, 因此这种称谓和理解非常直观的. 对于赋值量来说, 也是相同的道理.
之所以有"location"和"read"的说法, 是因为在C/C++中, 有很多表达式是表达可赋值单元的,
我们不能简单地理解"lvalue"就是变量. 如: a[i], *p, *(a->p+1), 等等. 这些都是C/C++的表达式,
不是变量, 故用"location"的含义可以避免很多误解. 请看下面的例子:
  const int x;
  x = 1;   // 这里 x 是 rvalue! 所以, 这是错误的赋值


相关文档:

通配符的 C 语言源代码

/* find files from wildcards, for MicroSoft C v4.0 */
/* ------------------------------------------------------------ */
/*   copyright 1986:      */
/*   Nourse Gregg & Browne, Inc.  */
/*   1 Horizon Road. #612 ......

C 的开始

    C 的开始
 
    2010年2月10日,
    开始阅读家里有关"C语言"的各种资料。
    使用 TurboC2.0,偶尔可能也会用到 Microsoft Visual C++ 6.0。 ......

系统设计 B/S结构和C/S结构

B/S结构(Browser/Server结构)结构即浏览器和服务器结构。它是随着Internet技术的兴起,对C/S结构的一种变化或者改进的结构。在这种结构下,用户工作界面是通过WWW浏览器来实现,极少部分事务逻辑在前端(Browser)实现,但是主要事务逻辑在服务器端(Server)实现,形成所谓三层3-tier结构。这样就大大简化了客户端电脑载 ......

c/c++中堆栈的区别

一、预备知识—程序的内存分配
一个由c/C++编译的程序占用的内存分为以下几个部分
1、栈区(stack)—    由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。
2、堆区(heap) —    一般由程序员分配释放, 若程序员不释放,程 ......

VIM一键编译C程序

    网上有好多篇文章讲如何配置.vimrc文件来实现VIM里一键编译,看了一下比较复杂。我一般没有什么大的程序要写,一般的小程序单个C文件就搞掂了,所以简化了一下网上的配置,在.vimrc里加上两行就满足我的需求了。
    set makeprg=gcc\ -Wall\ -o\ %<\ %
map <F7> :make<CR ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号