求教 一个奇怪的语句

软件和网站开发以及相关技术探讨
回复
头像
s4426565
帖子: 34
注册时间: 2007-10-24 1:37

求教 一个奇怪的语句

#1

帖子 s4426565 » 2008-03-07 1:49

我在SystemC 中看到了一个 很奇怪的语句不知道是什么意思 请教大家

a = b = c ;

SystemC是一种基于C++语言的用于系统设计的计算机语言,是用C++编写的一组库和宏
所以我想 这个语句应该还是C++ 或者C 支持的。 请高手执教 C++ 或 C 中有没有这样的语句
A man travels the world in search of what he needs and returns home to find it
头像
anticlockwise
帖子: 2394
注册时间: 2007-03-01 20:46
来自: 湖南长沙

#2

帖子 anticlockwise » 2008-03-07 4:24

有啊~~

其实就是将c 的值赋给 b 并且赋给 a
头像
s4426565
帖子: 34
注册时间: 2007-10-24 1:37

#3

帖子 s4426565 » 2008-03-07 15:39

是吗 我没有用过 谢谢 我试试 :D
A man travels the world in search of what he needs and returns home to find it
头像
yaoms
帖子: 4952
注册时间: 2007-10-19 14:51
来自: 深圳

#4

帖子 yaoms » 2008-03-07 15:48

...c语言里也有这个情况阿。不奇怪。
Nothing 有事请发邮件到 yms541 AT gmail.com
alias 爱慕颇雷尔='mplayer'
头像
s4426565
帖子: 34
注册时间: 2007-10-24 1:37

#5

帖子 s4426565 » 2008-03-07 15:55

谢谢 anticlockwise

我刚刚测试了一下 代码如下:

#include <stdio.h>

int main( void ){
int a = 1 ;
int b = 2 ;
int c = 0;
c = b = a;

printf( "a = %d\n",a );
printf( "b = %d\n",b );
printf( "c = %d\n",c );

a = 1;
b = 2;
c = 0;
c = a = b;

printf( "a = %d\n",a );
printf( "b = %d\n",b );
printf( "c = %d\n",c );

}


结果为 :

a = 1
b = 1
c = 1
a = 2
b = 2
c = 2

从结果看 x=y=z 中 x 和y 都是被 z 的值覆盖 如果 z等于2 则 执行完x =y=z 后x ,y 都为2

请大家指教我的理解对吗
A man travels the world in search of what he needs and returns home to find it
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#6

帖子 bones7456 » 2008-03-07 16:07

对!
关注我的blog: ε==3
回复