1、昆明理工大学C复习资料复习资料第一章 C语言基础基本内容1. 数据类型2. 常量3. 变量4. 表达式5. 运算符6. 格式化输入与输出7. 注释及语句1. 数据类型是根据各种数据所占存储单元大小不同而划分了不同的数据类型。C语言中的数据类型有基本类型、构造类型和指针类型。各种类型数据由于所占单元大小不同,故其所表示的范围也不一样。1)int, char, float, double are all basic data types in C language. (对)2)Provided that the length of int is 16 bits, then the value sc
2、ope of unsigned int is:(B)A0255 B065535 C.-3276832767 D-2562553)The declaration is: int k=0,a=0,b=0; unsigned long w=5; double x=1.42,y=0; then the incorrect expression is_A_Ay=x%3 B. w+= -2 C. x=w+5 D. k*=a+b4) In C, basic data types are int, char, float and _double_.5) Given declaration: char c=03
3、5; the size of c is _1_bytes.混合数据类型的运算1)Suppose declaration: char a=c; then statement: printf(“%d”,a); is wrong.(错)2)Suppose declaration: int a; float x,y;then the result data type of expression:x+a%3*(int)(x+y)%2/4 is _float_.3)The data type of expression: 18/4*sqrt(4.0) is float. (错)字符的ASCII值及其合理应
4、用1)Suppose declaration: char a; then expression: ch=5+9 is correct.(错)2) ASCII of A is 65.then read the following programand the result of it.Fill the blanks: main() char a; a=A+_11_; printf(“%c”,a); result: L3) To get a character with getchar(), you can input corresponding ASCII number of the desir
5、ed character from keybord.(错)表达式类型1) Suppose declaration: int a; float f; double i; then the result data type of expression: 10+a+i*f is _double_.2. 常量在程序运行过程中,其值不能被改变的量称为常量,常量区分为不同的类型。常量一般从其字面形式即可判别,也可以用一个标识符代表一个常量。字符常量的定义形式:#define PRICE 30字符常量定义后,在程序中不能再改变其值,如PRICE+是错误的。1) Incorrect string consta
6、nt is: (A) 字符串常量A. abc B. “1212” C. “0” D. “ ”2)If Rate is a symbol constant, we can use it as Rate+. (错)3. 变量其值可以改变的量称为变量。一个变量应该有一个名字,在内存中占据一定的存储单元,在该存储单元中存放变量的值。变量与声明:变量命名规则,大小写敏感1) As variable name, tmpvar and TmpVar are same. (错)2) Keywords can be used as variable names. (错)3)The first character
7、 of variable name must be a letter or a underscore (_). (对)4)Which of the following is error?(A) AKeywords can be used as variable names. BWe tend to use short names for local variables, especially loop indices, and longer names for external variables. CUpper case and lower case letters in variable
8、names are distinct. DThe first character of variable name must be a letter or a underscore (_).变量赋初值1)The statement: int n1=n2=10; is correct. (错)2)The declaration: float f=f+1.1; is correct. (错)3)Which of the following is the illegal variable names ?(D) ALad B. n_10 C. _567 D. g#k转义字符的应用1)Suppose d
9、eclaration: char c=010;then the count of character in variable c is _1_.当变量成为计数器和累加器的时候如何初始化1)When we use sum as an accumulating or a counting ,we should first initialized sum to _0_ 作为计数器或累加器的变量在使用之前必须初始化为0,防止原来的垃圾数据影响程序的执行。4. 运算符和表达式运算符:自增自减运算符,逗号运算符算术运算符,逗号运算符,1)The expression (x=y=w=0,y=5+w, x=y
10、) is wrong.。 (错)这是一个逗号运算符的题目,逗号运算符具有最低优先级,先计算,后取值。2)The result of expression: x=(i=4,j=16,k=32) is 32. (对)3)The operand of operator +/- can be variables or constants. (错)自增自减运算符只能用于变量不能用于常量。4)The % operator cannot be applied to a float or double. (对)%是取余数的运算符,只能用在整型数中。运算符的优先级和结合性Assignment operator
11、has the lowest precedence and a left-to-right associativity. (错)5. 格式化输入与输出1)Write the result of following program 5.2main() float a=5.23; printf(“%6.1f”,a);2)Suppose code segment: int k1,k2,k3,k4; scanf(“%d%d”,&k1,&k2); scanf(“%d,%d”,&k3,&k4);if we want k1,k3 get value 10, and k2,k4 get value 20, t
12、hen the accurate input is_10 2010,20_.6. 注释及语句C语言中,没有输入输出语句,只有输入输出函数.main函数的位置注释.不影响程序运行,编译时也不能发现其中的错误,注释的写法1)Comments have no effect to the performance of program. (对)2)C language has no input/output statement, just input/output functions instead. (对)3)Write the result of following program:(_11_)ma
13、in() int x=021; printf(“%x”,x);4)Write the result of following program:(_ 3.140000_)main() float a=3.14; printf(“%f”,a);5)In C, comments must begin with _/*_ and end with _*/_.6) A C program, whatever its size, consists of _ functions_ and variables.7) An expression becomes a statement when it is fo
14、llowed by a _;_.8) Value of the assignment expression:c=25 is _25_9) sum=sum+3 can be written as _ sum+=3_第二章 选择结构主要内容:1. 关系运算2. 选择语句的使用3. 文件包含命令1. 关系运算关系运算符 = = = = !=1)(x=y=z) is C language expression for relationship xyz. (错)2)Value of the expression a+1= =b is false. (错)逻辑运算符! & | |1)(x=y) & (x=
15、z) is C language expressionfor relationship xyz. (对)2)When a is 1 and b is 0, the value of a|b is true. (对)3)The declaration is: int x=2,y=4,z=5;which of the following expression equals to 0 ?(D)Ax & y B x=A)&(ch=y)&(y=z) B (x=y)and(y=z) C x=y=z D (x=Y)&(Y=z)4) The correct expresson for 1x10 and 100
16、y200 is _ (1=x & x=10) & (100=y & y=200)_.5) Having knowing: int x=3, y=4, z=5; among following expressions, whose value are not 0( A B C)A. x&y B. x=y C. x|y+z&y-z D. !(xx?w:yz?y:z is 4. (对)2)After running following block of program, value of variable m is ( D )int w=1,x=2,y=3,z=4,m;m=(wx)?w:x; m=(
17、my)?m:y; m=(mz)?m:z;A4 B 3 C 2 D 13) Suppose the following code segment: int w=1,x=2,y=3,z=4,m; m=(wx)?w:x; m=(my)?m:y; m=(mz)?m:z;finally the value of m is _1_.2. if语句1)The statement: if (x=y)&(x!=0) x+y; is correct. (错)2)The statement if (xy) x=y , else x=-y, is not correct. (对)3)The statement if
18、(n) means if n is not 0. (对)4)The result of the following program is( C ) main() int i=1,j=1,k=2; if(j+|k+)& i+) printf(%d,%d,%dn,i,j,k);A1,1,2 B 2,2,1 C 2,2,2 D 2,2,35) Read the following program and the result of it. Fill the blanks.main() int _a=1_,b=2,c=3; if (c=a) printf(“%dn”,c); else printf(“
19、%dn”,b);result: 1 (?) 35) If we use the following four expressions as control expression for if statement, which one has different meanings to others?(D)A. k%2 B. k%2 = 1 C. (k%2)!=0 D. k%2 = 06) main() int a=100,x=10,y=20,ok1=5,ok2=1; if(xy) if(y!=10) if(!ok1) a=1; else if(ok2) a=10;finally the val
20、ue of a is _10_.7) The piece of program will output whether a year is a leap year or not. Leap year:could divided by 4 but could not divided by 100;(2) could divided by 400.main()int year,leap; printf(“input year:”); scanf(“%d”,&year); if(year%400=0) _ leap=1_; else if(year%4=0)&(year%100!=0)leap=1;
21、 else leap=0;if(leap!=_1_) printf(“%d is a leap yearn”,year);else printf(“%d is not a leap yearn”,year);8) Having known :int a=1,b=2,c=3,x;,after running following block of program,,the satements which enable value of x to be 3 are_ A D _。A. if(ca) x=1; else if(b3) x=3; else if(a2) x=2; else x=1;C.
22、if(a3) x=1; if(a2) x=2; if(a1) x=3; D. if(ab) x=b; if(bC) x=c; if(ca) x=a;9) C language request in embeded if statement ,the use of else must be 与离它最近的上方的一个if匹配。3. switch语句1)The switch statement is a multi-way decision. (对)2)In the statement switch(expression), expression can be any type. (错)3)The r
23、esult of the following program is( C )main()int i=0;if (i=5)i+;switch(i%5)case 0: printf(“*”); break;case 1: printf(“#”); break;default: printf(“n”);case 2: printf(“&”);A#& B #* C # D &4) main() int x=1,y=0,a=0,b=0; switch(x) case 1: switch(y) case 0: a+; break; case 1: b+;break; case 2: a+;b+;break
24、; case 3: a+;b+; printf(a=%d,b=%d,a,b);The running result is _ a=2,b=1_.第三章 循环结构主要内容:1. for循环1)The statement: for (a=0,b=1,i=0; i=200; i+) is correct . (对)2)The result of the following block of program is:(D) for(x=3;x6; x+) if(x%2 !=0) printf(“*%d”,x); else printf(“#%dn”,x); A*3 #4*5 B #3*4#5 C #3*
25、4#5 D *3#4*53)Write the result of following program:(_23_)main() int count; count=2; for(; count=20;count+=3); printf(%d,count);4)Write the result of the following program: The max value is 27#include int findMax(int , int);int main() int nums5=2,18,1,27,16; printf(The max value is %d,findMax(nums,5
26、);int findMax(int vals, int numels) int i, max=vals0; for(i=1;inumels;i+) if(max=0)iArri=100;i-;This program segment can not be replaced with(D)Aint i=4,iArr5; while(i=0) iArri-=100; Bint i=4,iArr5; while(i=0) iArri=100; i-=1; Cint i=4,iArr5; for(;i=0;i-) iArri=100; Dint i=4,iArr5; for(i=0;i=0;i+) i
27、Arri=100; 3)Write the result of following program:(_21_)main() int num=0; while(num=20) num+; printf(%d,num);3. dowhile循环1)In do-while, the loop is executed at lest once. (对)2)The result of the following program is: (A) int a=1,b=1; do a+; b-; while(b0); printf(“a=%d,b=%dn”,a,b);Aa=2,b=0 B a=1,b=1 C
28、 a=3,b=-1 D a=2,b=14. 空语句的使用1)A null statement has no effect to the performance of program. (错)第四章 函数主要内容:1. 函数的定义2. 函数参数和函数的值3. 函数调用4. 数组作为函数参数5. 局部变量和全部变量6. 动态存储变量和静态存储变量7. 宏定义1. 函数的定义1)Which of the following function definitions is correct?(A) Adouble fun(int x, int y) B double fun(int x; int y) Cdouble fun(int x, y) D double fun(int x, y;)2) Which of the following statements is correct?(A) A. C programs generally consist of many small functions . B. Functi