易截截图软件、单文件、免安装、纯绿色、仅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/C++中时间函数的介绍

1.概念
       在C/C++中,对字符串的操作有很多值得注意的问题,同样,C/C++对时间的操作也有许多值得大家注意的地方。最近,在技术群中有很多网友也多次问到过C++语言中对时间的操作、获取和显示等等的问题。下面,在这篇文章中,笔者将主要介绍在C/C++中时间和日期的使用方法.  ......

Ubuntu(Linux)使用Eclipse搭建C/C++编译环境

这两天,给自己电脑弄了双系统,除了原来的Windows 7系统外,装上了Linux系统,使用的版本是Ubuntu
(点
击可到相应的下载页面)。开始我装的Linux版本是fedora9,对于一个根本没接触过Linux系统的人而言,使用fedora,简直让人崩溃。更
崩溃的是,我用的英文版。没的办法,又重新下载Linux,刻碟。装系统。装系统的时候 ......

C#中C/C++程序员注意问题

 1、C/C++程序员请注意,不能在case语句不为空时“向下执行”。
  2、值类型和引用类型之间的区别:C#的基本类型(int,char等)都是值类型,是在栈中创建的。而对象是引用类型,创建于堆中,需要使用关键字new。
  3、在C#中通过实例访问静态方法或成员变量是不合法的,会生成编译器错误。但是我们可以 ......

error:cannot get C/H/S values

windows7 + ubuntu9.10双启动,这个有太多的帖子了,不过这次的情况比较复杂.
先装的WIN7,后装UBUNTU,没有任何问题.GRUB双启动.
后来因为一个情况,要装XP,把WIN7做了 ghost.装完XP,GRUB当然没有了,于是用ubuntu启动盘修复.
虽然启动菜单出来了,但只能进行ubuntu,进入windows的时候就提示error:cannot get C/H/S value ......

学c的很多

c学的人很多。但十之八九是半桶水。或者写得很死。也许我这话有点偏激。但是我给出一个标准吧。你能写出像linux内核代码这样的代码吗?其实任何一门语言的精髓,在于运用。所以在学习之前最好问一问我为什要学这门语言。如果是为学而学,学到最后又是半桶水。还真的不如看小说来得刺激。没有目的干事情,本身就是一种浪费。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号