当前位置:文档之家› 双语C复习资料.doc

双语C复习资料.doc

双语C复习资料.doc
双语C复习资料.doc

复习资料

第一章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 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___)

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;

if(x

if(y!=10)

if(!ok1)

a=1;

else if(ok2) a=10;

}

finally the value 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;

else leap=0;

if(leap!=_1___) printf(“%d is a leap year\n”,year);

else printf(“%d is not a leap year\n”,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(c

B. if(a>3) x=3; else if(a<2) x=2; else x=1;

C. if(a<3) x=1; if(a<2) x=2; if(a<1) x=3;

D. if(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 result of the following program is( C )

main()

{int i=0;

Iif (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;

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;x<6; x++)

{

if(x%2 !=0)

printf(“**%d”,x);

else

printf(“##%d\n”,x);

}

A.**3 ##4**5 B ##3**4##5 C ##3**4##5 D **3##4**5 3)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 nums[5]={2,18,1,27,16};

printf("The max value is %d",findMax(nums,5));

}

int findMax(int vals[], int numels)

{

int i, max=vals[0];

for(i=1;i

if(max

max=vals[i];

return (max);

}

2.while循环

1)Suppose code segment:

int k=10;

while (k=0)

k=k-1;

then the loop will execute 10 times. (错)

2)Read the following program:

int i=4,iArr[5];

while(i>=0)

{

iArr[i]=100;

i--;

}

This program segment can not be replaced with(D)

A.int i=4,iArr[5]; while(i>=0) { iArr[i--]=100; }

B.int i=4,iArr[5]; while(i>=0) { iArr[i]=100; i-=1; }

C.int i=4,iArr[5]; for(;i>=0;i--) { iArr[i]=100; }

D.int i=4,iArr[5]; for(i=0;i>=0;i++) {iArr[i]=100; }

3)Write the result of following program:(__21____)

main()

{

int num=0;

while(num<=20)

num++;

printf("%d",num);}

3.do…while循环

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(b<0);

printf(“a=%d,b=%d\n”,a,b);

A.a=2,b=0 B a=1,b=1 C a=3,b=-1 D a=2,b=1

4.空语句的使用

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)

A.double fun(int x, int y) B double fun(int x; int y)

C.double 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. Functions may be defined within other functions.

C. In C program, you have to put main() function before all other functions.

D. In C, a function has to be defined before any other code can call it.

2.函数参数和函数的值

1)When we use function,we have two methods to pass value from the calling function to the called function:pass by value and pass by reference. (对)

2) In C language, some functions needs return no value , which keywords is used to denote this?(A)

A. void

B. int

C. float

D. double

3) Write the result of the following program a=4,b=3

include

swap(int *, int *);

main()

{

int a=3,b=4;

swap(&a,&b);

printf("a=%d,b=%d",a,b);

}

swap(int *x, int *y)

{

int tmp;

tmp=*x;

*x=*y;

*y=tmp;

}

3. 函数调用

1) Which one is the result of the following program?(D)

void fun(char c,int d)

{

c=c+1;

d=d+1;

printf("%c,%c,",c,d);

}

main()

{

char a='A', b='a';

fun(b,a);

printf("%c,%c\n",a,b);

}

A. B,b,A,a

B. B,a,B,a

C. A,a,B,b

D. b,B,A,a

3.数组作为函数参数

1) Write the result of following program: (B)

fun(char p[][10])

{ int n=0,i;

for(i=0;i<7;i++)

if(p[i][0]=='T')n++;

return n;

}

main()

{ char str[][10]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};

printf("%d\n",fun(str));

}

A. 1

B. 2

C. 3

D. 4

4.局部变量和全部变量

1)Local variables of the same name in different functions are unrelated. (对)

2)The variables defined within any function is global variables. (错)

5.动态存储变量和静态存储变量

1)Choose the result of the following program (B)

A. 1 1 1 B 1 2 3 C 0 1 2 D 0 0 0

increment()

{

static int x=0;

x+=1;

printf("%d " , x );

}

main()

{

increment();increment();increment();

}

6.宏定义

1)Fill the blank to change values of a and b . #define MYSW AP(z,x,y) {z=x; x=y;

y=z;}float a=5,b=16,c;MYSWAP( _c_ ,a,b); 2)Read program as follows,then write the result:__7__ 3)

#define MAX(x,y) (x)>(y)?(x):(y)

main()

{

int a=5,b=2,c=3,d=3,t;

t=MAX(a+b,c+d)*10;

printf(“%d\n”,t);

}

第五章数组

主要内容:

1.一维数组

2.二维数组

3.字符数组

1.一维数组

定义

引用

初始化

1)Array initialization: int grade[5]={1,2,3,4}; So the value of grade[5] is 5 (错)2.二维数组

定义

引用

1)Write the result of following program: 30

main()

{ int a[3][3]={{1,2,9},{3,4,8},{5,6,7}},i,s=0;

for(i=0;i<3;i++) s+=a[i][i]+a[i][3-i-1];

printf("%d\n",s);

}

初始化

3.字符数组

定义

初始化

引用

字符串和字符串结束标志

1)Suppose the declaration:

char x[]={"abcdefg"};

char y[]={'a','b','c','d','e','f','g'};

then array x and array y have same storage size. (错)

2)Which of the following string assignment statements is correct? (B)

A.string s="abcde"; B. static char s[ ]={"abcde"};

C.str s="abcde"; D char s="abcde";

3)Choose the result of the following program:(B)

#include

void main(void)

{

char c[]={'a','b','c','d','\0'},*p_c;

p_c=c;

c[2]='\0';

printf("%s",c);

}

A.a B. ab C abc D. abcd

1)Write the result of following program:(__hELLO!____) main()

{

char s[80],*sp="HELLO!";

sp=strcpy(s,sp);

s[0]='h';

puts(sp);

}

字符串处理函数

1)The result of strcmp("STUDY","study") is 0. (错)

主要内容:

1.指针与变量

2.数组与指针

1.指针与变量

1)A pointer contains the address of a variable. (对)

2)Find the output of the following program (D)

point(char *p){p+=3;}

main()

{char b[4]={'a','b','c','d'},*p=b;

point(p);printf("%c\n",*p);

}

A.a B b C c D d

3) Provided that the declaration is:

int *p ,m=5,n;

which of the following statements is correct? (D)

A. p=&n; scanf(“%d”, &p);

B. p=&n; scanf(“%d”,*p);

C. scanf(“%d”,&n);*p=n;

D. p=&n; *p=m;

2.数组与指针

1)Suppose the declaration:

char *Line[5];

It will produce five pointers to char. (对)

2)Array: float prices[5]={1,2,3};

Pointer: float *pi;

If pi=&prices[1], which of the following is the value of *pi++?(D)A.0 B 1 C 2 D 3

3)int *a[5] refers to(A)

A.array of pointers B pointer to an array

C. pointer to a pointer D none of these

第七章结构体

主要内容

1.结构体的定义和使用

2.共用体的定义和使用

1.结构体的定义和使用

1)Provided that the sizeof(int) equals 4,then the result of the following program is: (A)# include “stdio.h”

struct date

{

int year,month,day;

}today;

main()

{

printf( “%d\n”,sizeof(today));

}

A.12 B 8 C 10 D 9

2)#include "stdio.h"

#include "math.h"

struct TPoint

{ float x;

float y;

};

main()

{ struct TPoint p1;

float fDist;

p1.x=3;

p2.y=4;

fDist=sqrt(p1.x * p1.x + p1.y * p1.y);

printf("The distance between p1 to origin is:

%4.2f\n",fDist);

}

The output of the program is:

The distance between p1 to origin is:__ 5.00_____

2. 共用体的定义和使用

1)Choose the result of the following program :(B)

#include "stdio.h"

union Node

{

char Name[3];

char Type[2];

};

main()

{ union Node a;

https://www.doczj.com/doc/5916790517.html,[2]='\0';

a.Type[0]='L';

a.Type[1]='M';

printf("%s\n",https://www.doczj.com/doc/5916790517.html,);

}

A.L B LM C M D 0

2)All members of a union are stored in the same area in memory. (对)

1.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(c

B.i f(a>3) x=3; else if(a<2) x=2; else x=1;

C.i f(a<3) x=1; if(a<2) x=2; if(a<1) x=3;

D.if(a

2.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

3. The correct two-dimesional arrays initilization are A B

A.int a[2][3]={{1,2,3},{3,4,5}};

B.int a[ ][3]={1,2,3,4,5,6};

C.int a[2][ ]={1,2,3,4,5,6};

D.int a[2][ ]={{1,2},{3,4}};

4. The individual elments are stored sequentially in an array A B D

A.The individual elments are stored sequentially in an array

B.F or a single-dimensional array,the first element has an index of 0.

C.I f an array has been declared as consisting of 10 elments,the max index is 10.

D.The size of an single-dimensional may be omitted when initializing values are included in the declaration statement

5. Given the piece of code

int a[50];

int *pa;

pa=a;

To access the 6th element of the array which of the following is correct? A B C

A.*(a+5) B a[5] C pa[5] D *(*pa + 5)

1.Write a function named strcpy,which copies the contents of string2 to string1.

参考程序:

void strcpy(char string1[[],char string2[])

{

int i=0;

while(string2[i]!=’\0’)

{

string1[i]=string2[i];

i++;

}

string1[i]=’\0’;

return;

}

2.Write a program which calculate sum of diagonal of a 3*3 matrix.(矩阵对角线)

参考程序:

#include main()

{

int a[3][3],sum=0;

int i,j;

printf(“Enter data:\n”);

for(i=0;i<3;i++)

for(j=0;j<3;j++)

scanf(“%d”,&a[i][j]);

for(i=0;i<3;i++)

sum=sum+a[i][i];

printf(“sum=%5d\n”,sum);

}

3.Input three integer numbers x,y and z. Output them from the less one to the bigger one.

#include

main()

{

int x,y,z,t;

scanf("%d,%d,%d",&x,&y,&z);

if(x>y)

{t=x;x=y;y=t;}

if(x>z)

{t=x;x=z;z=t;}

if(y>z)

{t=y;y=z;z=t;}

printf("%d %d %d\n",x,y,z);

}

}

4.Input a character, and tell wheather the character is a letter, digit or a special character.

参考程序:

#include

main()

{

char c;

c=getchar();

if(c>='a'&&c<='z'||c>='A'&&c<='Z')

printf("%c is a letter\n",c);

else if(c>='0'&&c<='9')

printf("%c is a digit \n",c);

else

printf("%c is a spicial character\n",c);

}

5.Programming to get the result of the expression as :1+2+3+ (100)

参考程序:

#include

int main( )

{

int k;

int sum;

k=1;

sum=0;

for (k=1;k<=100;k++)

sum=sum+k;

printf("%d \n", sum);

return 0;

}

6.Write a program that prompts the user for a number and then prints message telling whether

the digit is odd or even.

参考程序:

#include

main()

{

int a;

printf("Input a digit number: ");

scanf("%d",&a);

if (a/2==(float)a/2)

printf("\n%d is an even number.\n",a);

else

相关主题
文本预览
相关文档 最新文档