26-复习题
3.10 复习题
复习题的参考答案在附录A中。
1.指出下面各种数据使用的合适数据类型(有些可使用多种数据类型):
a.East Simpleton的人口
b.DVD影碟的价格
c.本章出现次数最多的字母
d.本章出现次数最多的字母次数
2.在什么情况下要用long类型的变量代替int类型的变量?
3.使用哪些可移植的数据类型可以获得32位有符号整数?选择的理由是什么?
4.指出下列常量的类型和含义(如果有的话):
a
. '\b'
b. 1066
c. 99.44
d
. 0XAA
e
. 2.0e30
5.Dottie Cawm编写了一个程序,请找出程序中的错误。
include <stdio.h>
main
(
float g; h;
float tax, rate;
g = e21;
tax = rate*g;
)
6.写出下列常量在声明中使用的数据类型和在 printf()
中对应的转换说明:
| 常量 | 类型 | 转换说明( %
转换字符) |
| :----- | :----- | :----- | :----- | :----- |
| 12
|
| 0X3
|
| 'C'
|
| 2.34E07
|
| '\040'
|
| 7.0
|
| 6L
|
| 6.0f
|
| 0x5.b6p12
|
7.写出下列常量在声明中使用的数据类型和在 printf()
中对应的转换说明(假设 int
为 16
位):
| 常量 | 类型 | 转换说明( %
转换字符) |
| :----- | :----- | :----- | :----- | :----- |
| 012
|
| 2.9e05L
|
| 's'
|
| 100000
|
| '\n'
|
| 20.0f
|
| 0x44
|
| -40
|
8.假设程序的开头有下列声明:
int imate = 2;
long shot = 53456;
char grade = 'A';
float log = 2.71828;
把下面 printf()
语句中的转换字符补充完整:
printf("The odds against the %__ were %__ to 1.\n", imate, shot);
printf("A score of %__ is not an %__ grade.\n", log, grade);
9.假设 ch
是 char
类型的变量。分别使用转义序列、十进制值、八进制字符常量和十六进制字符常量把回车字符赋给 ch
(假设使用 ASCII
编码值)。
10.修正下面的程序(在C中, /
表示除以)。
void main(int) / this program is perfect /
{
cows, legs integer;
printf("How many cow legs did you count?\n);
scanf("%c", legs);
cows = legs / 4;
printf("That implies there are %f cows.\n", cows)
}
11.指出下列转义序列的含义:
a
. \n
b. \\
c. \"
d
. \t