1.指出下面各種數(shù)據(jù)使用的合適的數(shù)據(jù)類型(有些可使用多種數(shù)據(jù)類型)?
a.East Simpletion的人口? ? ? ? int\short int\unsigned short
b.DVD光盤的價(jià)格? ? ? ? ? ? ? ? float\double\
c.本章出現(xiàn)次數(shù)最多的字母? ? ? ? ? char\
d.本章出現(xiàn)次數(shù)最多的字母的次數(shù)? ?int \unsigned int
2.在什么情況下要用long類型的變量代替int類型的變量?
在系統(tǒng)中要表示的數(shù)超過(guò)了int可表示的范圍,這是要使用long類型。
如果要處理更大的值,那么使用一種在所有系統(tǒng)上都保證至少是32位的類型,可提高程序的可移植性。
3.使用哪些可移植的數(shù)據(jù)類型可以獲得32位有符號(hào)整數(shù)?選擇的理由是什么?
如果正好要獲得32位的整數(shù),可以使用int32_t類型。
要獲得可存儲(chǔ)至少32位整數(shù)的最小類型,可以使用int_least32_t類型。
如果要為32位整數(shù)提供最快的計(jì)算速度,可以選擇int_fast32_t類型
4.指出下列常量的類型和含義(如果有的話):
'\b' char類型常亮 但是存儲(chǔ)位int類型
1066 int類型
99.44 double類型
0XAA 16進(jìn)制int類型
2.0e30? double類型
5.Dittue Cawm編寫了一個(gè)程序,請(qǐng)找出程序中的錯(cuò)誤。
#include
(int) main {
float g, h;
float tax, rate;
g = 1.e21? ?e前面至少要有一個(gè)數(shù)字;
tax = rate*g;
return 0;
}
6.寫出下列常量在聲明中使用的數(shù)據(jù)類型和在printf()中對(duì)應(yīng)的轉(zhuǎn)換說(shuō)明:
Constant? ? ? ? ? ? ? ? ?Type? ? ? ? ? ? ? ? ? ? Specifier
12? ? ? ? ? ? ? ? ? ? ? ? ?int? ? ? ? ? ? ? ? ? ? ? ? ? ? %d
0x3? ? ? ? ? ? ? ? ? ? ?unsigned int? ? ? ? ? ? ? ? %#x
'c'? ? ? ? ? ? ? ? ? ? ?char? ? ? ? ? ? ? ? ? ? ? ? %c
2.34E07? ? ? ? ? ? ? ? ?double? ? ? ? ? ? ? ? ? ? ? ? %e
'\040'? ? ? ? ? ? ? ? ? ? ?char? ? ? ? ? ? ? ? ? ? ? ? %c
7.0? ? ? ? ? ? ? ? ? ? ?double? ? ? ? ? ? ? ? ? ? ? ? %f
6L? ? ? ? ? ? ? ? ? ? ? ? ?long int? ? ? ? ? ? ? ? ? ? %ld
6.0f? ? ? ? ? ? ? ? ? ? ?float? ? ? ? ? ? ? ? ? ? ? ? %f
0x5.b6p12? ? ? ? ? ? ? ? ?float? ? ? ? ? ? ? ? ? ? ? ? %a
7.寫出下列常量在聲明中使用的數(shù)據(jù)類型和在printf()中對(duì)應(yīng)的轉(zhuǎn)換說(shuō)明(假設(shè)int為16位)
Constant? ? ? ? ? ? ? ? ?Type? ? ? ? ? ? ? ? ? ? Specifier
012? ? ? ? ? ? ? ? ? ? ?int? ? ? ? ? ? ? ? ? ? ? ? %#o
2.9e05L? ? ? ? ? ? ? ? ?long double? ? ? ? ? ? ? ? %le
's'? ? ? ? ? ? ? ? ? ? ?char? ? ? ? ? ? ? ? ? ? %c
100000? ? ? ? ? ? ? ? ? ? ?long int? ? ? ? ? ? ? ? %ld
'\n'? ? ? ? ? ? ? ? ? ? ?char? ? ? ? ? ? ? ? ? ? %c
20.0f? ? ? ? ? ? ? ? ? ? ?float? ? ? ? ? ? ? ? ? ? %f
0x44? ? ? ? ? ? ? ? ? ? ?unsigned? ? ? ? ? ? ? ? %x
-40? ? ? ? ? ? ? ? ? ? ?int? ? ? ? ? ? ? ? ? ? ? ? %d
8.假設(shè)程序的開(kāi)頭有下列聲明:
int imate = 2;
long short = 53456;
char grade = 'a';
float log = 2.71828;
print("The odds against the %d were %ld to 1.\n",imagte, short);
print("A score of %f is not an %c grade.\n",log, grade);
9.假設(shè)ch是char類型的變量,分別使用轉(zhuǎn)義序列、十進(jìn)制值、八進(jìn)制字符常量和十六進(jìn)制字符常量把回車字符賦值給ch(假設(shè)使用ASCII編碼值)
轉(zhuǎn)義字符 char ch=? ? '\r';
十進(jìn)制值 char ch='13'
八進(jìn)制 char ch='\015'
十六進(jìn)制 char ch='\xd'
10.修正下列程序
void main(int) /* this program is perfect */
{
int cows, legs;
printf("How many cow legs did you count?\n");
scanf("%d", legs);
cows = legs / 4;
printf("That implies there are %d cows.\n", cows)
}
11.指出下列轉(zhuǎn)義序列的含義
a. \n? 換行
b. \\? 反斜杠
c. \"? 雙引號(hào)
d. \t? 制表符