本文共 338 字,大约阅读时间需要 1 分钟。
实验目的:掌握条件操作符
实验步骤:
1.条件表达式i>j?++i:++j是如何求值的?为什么?编程验证。
怎样看条件操作符和if-else结构的关系?
2. if(a > b)
max = a;
else
max = b;
可以改写为(a > b)?(max = a):(max = b),其中的括号可能去掉吗?为什么?
还可以改写为 。
3.用条件操作符改写下面的if-else结构。(用两种方式)
if(a>b)
printf("%d\n", a);
else
printf("%d\n", b);
4.分析表达式a > b ? a : c > d ? c++ : d++。
注意:
分析完如何求值后,还应分析此表达式的可读性。
转载地址:http://kddti.baihongyu.com/