论坛: 编程破解 标题: c问题 复制本贴地址    
作者: netax [netax]    论坛用户   登录
main()
{
 int x=6,y=6,z=3;
 z+=x>y?x++:y++;
 printf("%d\t%d\t%d",x,y,z);
}
结果一运行就知,我需要的是解的过程,谢谢!

地主 发表时间: 06/14 00:09

回复: xhw_73 [xhw_73]   论坛用户   登录
书上有!

B1层 发表时间: 06/14 10:20

回复: netax [netax]   论坛用户   登录
我的书上只有答案,没有为什么!
请问你用的是哪本书?

B2层 发表时间: 06/14 10:59

回复: rain_night [rain_night]   论坛用户   登录
看下优先级和运算方向,在实际中不会出现这的。
中国的考试和教育就这样。

B3层 发表时间: 06/14 16:56

回复: bidisty [bidisty]   论坛用户   登录
分别是:
7
7
10

B4层 发表时间: 06/14 17:02

回复: Sdary [sdary]   论坛用户   登录
running the program , the result should be like this :
6 7 9
reason:

1. "x>y" equal FALSE,  so "y++"be the case, "x++"ignored
2. now it should be like this: z+=y++;
3. first"z+=y" executed , result:x=6,y=6,z=z+y=3+6=9
   second "y++" executed , result: x=6,y=7,z=9
4. end 


B5层 发表时间: 06/14 20:11

回复: netax [netax]   论坛用户   登录
great~
thx ,sdary!
most person  regard it as (z+=x>y)?x++:y++,but not z+=(x>y?x++:y++),so we were wrong!

 can u tell me your oicq?


B6层 发表时间: 06/15 23:06

回复: huangwen [huangwen]   论坛用户   登录
main()
{
 int x=6,y=6,z=3;
 z+=x>y?x++:y++;
 printf("%d\t%d\t%d",x,y,z);
}
首先要知道算法的优先级?
先是和X++和Y++各等于7
再执行三目运算:x不大于y所以赋值X++给表达式;
z+=7;
z=z+7;
所以整个语句等于:10


B7层 发表时间: 06/16 09:10

回复: cyh811122 [cyh811122]   论坛用户   登录
根据优先级就应该知道 了


B8层 发表时间: 06/16 16:43

回复: lindayi [lindayi]   论坛用户   登录
不会吧老大,这应该没有什么问题啊,运算符的语法懂了不就明白了

B9层 发表时间: 06/16 21:25

回复: tommy_he [tommy_he]   版主   登录
同意楼上的!好象没有什么问题嘛!很简单的语句啊!

B10层 发表时间: 06/17 18:27

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号