复习资料
第一章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 scope of unsigned int is:(B)
A.0~255 B.0~65535 C.-32768~32767 D.-256~255
3)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__
A.y=x%3 B. w+= -2 C. x=w+5 D. k*=a+b
4) In C, basic data types are int, char, float and _double_____.
5) Given declaration: char c=’\035’; 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值及其合理应用
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: L
3) To get a character with getchar(), you can input corresponding ASCII number of the desired character from keybord.(错)
表达式类型
1)Suppose declaration:
2)int a;
3)float f;
4)double i;
5)then the result data type of expression:
6)10+’a’+i*f is __double____.
2.常量
在程序运行过程中,其值不能被改变的量称为常量,常量区分为不同的类型。常量一般从其字面形式即可判别,也可以用一个标识符代表一个常量。
字符常量的定义形式:
#define PRICE 30
字符常量定义后,在程序中不能再改变其值,如PRICE++是错误的。
1)Incorrect string constant 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 of variable name must be a letter or a underscore (_). (对)
4)Which of the following is error?(A)
A.Keywords can be used as variable names.
B.We tend to use short names for local variables, especially loop indices, and longer names for external variables.
C.Upper case and lower case letters in variable names are distinct.
D.The 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)
A.Lad B. n_10 C. _567 D. g#k
转义字符的应用
1)Suppose declaration: 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)" 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 has the lowest precedence and a left-to-right associativity. (错)
5. 格式化输入与输出
1)Write the result of following program 5.2
main()
{
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,
then the accurate input is___10 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___)
main()
{
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 statementwhen it is followed 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 x≤y≤z. (错)
2)Value of the expression ‘a’+1==’b’ is false. (错)
逻辑运算符
!&& | |
1)(x<=y) && (x<=z) is C language expressionfor relationship x≤y≤z. (对)
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)
A.x && y B x<=y C x||y+z&&y-z D !z
4)In the following operators, which one has the lowest precedence?(C)
A. *
B. &
C. | |
D. =
关系表达式
1)The result of expression: 3&&5||1%2 is 1. (对)
2)(ch>='A')&(ch<='Z')can tell you wheather variable ch is uppercase. (错)
3)Which one can express x≥y≥z correctly?( A )
A (x>=y)&&(y>=z)
B (x>=y)and(y>=z)
C x>=y>=z
D (x>=Y)&&(Y>=z)
4) The correct expresson for 1≤x≤10 and 100≤x≤200 is _ (1<=x<=10) && (100<=x<=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. !((x 条件运算符及条件表达式 1)Suppose declaration: w=1,x=2,y=3,z=4;then the value of w>x?w:y>z?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=(w A.4 B 3 C 2 D 1 3) Suppose the following code segment: int w=1,x=2,y=3,z=4,m; m=(w m=(m m=(m 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 (x 3)The statement if (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,%d\n",i,j,k); } A.1,1,2 B 2,2,1 C 2,2,2 D 2,2,3 5) Read the following program and the result of it. Fill the blanks. main() { int _a=1_____,b=2,c=3; if (c=a) printf(“%d\n”,c); else printf(“%d\n”,b); } result: 1 5) 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 == 0 6) main() { int a=100,x=10,y=20,ok1=5,ok2=1;