第四章和第五章答案
第四章
3.下面这样使用代码块是为了?
statement
{
statement
statement
}
statement
A:This is useful if you need to introduce a temporary variable for the enclosed statements,but wish to restrict access to the variable to only those statements.
12.对于if语句,先处理最特殊的任务。
第五章
5.一个表达式表示年份:
leap_year = year % 400 || ( year % 100 != 0 && year % 4 == 0 )
6.具有副作用的操作符:
1)()操作符本身并没有任何副作用,但它所调用的函数可能有;
2)++,--
3)=
7.同一种优先级的且结合性从左到右的表达式会不会求值顺序不明,如:a<=b<=c。
答案显示的是没有,但很是疑惑。如x+y+1书中明明就说了是不明的。
而优先级只对相邻operator的执行顺序起作用,在如:a*b + c*d + e*f中,只要保证每个
乘法运算在它相邻的加法运算之前执行即可。
8消除下列代码的多余代码。
a = f1(x);
b = f2(x+a);
for (c = f3(a, b); c > 0; c = f3(a, b))
{
statements
a = f1(++x);
b = f2(x + a);
}
My answer:
while (a = f1(++x),b = f2(x+a), c = f3(a, b),c > 0)
statements
Actually:
for (a = f1(x); b = f2(x+a), c = f3(a, b), c > 0; a = f1(++x) )
statements
在for语句的第二个分号前的expression2,是每次执行statements之前都要执行的。
9.一个相加为零的数组的元素不一定都是0.(这小学生都知道了吧⊙﹏⊙b)
10.-7%-5=-2; -7%5=-2; 7%-5=2;

浙公网安备 33010602011771号