昆明理工大学C复习资料.docx
《昆明理工大学C复习资料.docx》由会员分享,可在线阅读,更多相关《昆明理工大学C复习资料.docx(22页珍藏版)》请在冰豆网上搜索。
昆明理工大学C复习资料
复习资料
第一章C语言基础
基本内容
1.数据类型
2.常量
3.变量
4.表达式
5.运算符
6.格式化输入与输出
7.注释及语句
1.数据类型
是根据各种数据所占存储单元大小不同而划分了不同的数据类型。
C语言中的数据类型有基本类型、构造类型和指针类型。
各种类型数据由于所占单元大小不同,故其所表示的范围也不一样。
1)int,char,float,doubleareallbasicdatatypesinClanguage.(对)
2)Providedthatthelengthofintis16bits,thenthevaluescopeofunsignedintis:
(B)
A.0~255B.0~65535C.-32768~32767D.-256~255
3)Thedeclarationis:
intk=0,a=0,b=0;unsignedlongw=5;doublex=1.42,y=0;thentheincorrectexpressionis_A__
A.y=x%3B.w+=-2C.x=w+5D.k*=a+b
4)InC,basicdatatypesareint,char,floatand_double_____.
5)Givendeclaration:
charc=’\035’;thesizeofcis__1____bytes.
混合数据类型的运算
1)Supposedeclaration:
chara=’c’;thenstatement:
printf(“%d”,a);iswrong.(错)
2)Supposedeclaration:
inta;
floatx,y;
thentheresultdatatypeofexpression:
x+a%3*(int)(x+y)%2/4is_float_____.
3)Thedatatypeofexpression:
18/4*sqrt(4.0)isfloat.(错)
字符的ASCII值及其合理应用
1)Supposedeclaration:
chara;thenexpression:
ch=’5+9’iscorrect.(错)
2)ASCIIof‘A’is65.thenreadthefollowingprogramandtheresultofit.Filltheblanks:
main(){chara;a=’A’+__11____;printf(“%c”,a);}result:
L
3)Togetacharacterwithgetchar(),youcaninputcorrespondingASCIInumberofthedesiredcharacterfromkeybord.(错)
表达式类型
1)Supposedeclaration:
inta;floatf;doublei;thentheresultdatatypeofexpression:
10+’a’+i*fis__double____.
2.常量
在程序运行过程中,其值不能被改变的量称为常量,常量区分为不同的类型。
常量一般从其字面形式即可判别,也可以用一个标识符代表一个常量。
字符常量的定义形式:
#definePRICE30
字符常量定义后,在程序中不能再改变其值,如PRICE++是错误的。
1)Incorrectstringconstantis:
(A)字符串常量
A.‘abc’B.“1212”C.“0”D.“”
2)IfRateisasymbolconstant,wecanuseitasRate++.(错)
3.变量
其值可以改变的量称为变量。
一个变量应该有一个名字,在内存中占据一定的存储单元,在该存储单元中存放变量的值。
变量与声明:
变量命名规则,大小写敏感
1)Asvariablename,tmpvarandTmpVararesame.(错)
2)Keywordscanbeusedasvariablenames.(错)
3)Thefirstcharacterofvariablenamemustbealetteroraunderscore(_).(对)
4)Whichofthefollowingiserror?
(A)
A.Keywordscanbeusedasvariablenames.
B.Wetendtouseshortnamesforlocalvariables,especiallyloopindices,andlongernamesforexternalvariables.
C.Uppercaseandlowercaselettersinvariablenamesaredistinct.
D.Thefirstcharacterofvariablenamemustbealetteroraunderscore(_).
变量赋初值
1)Thestatement:
intn1=n2=10;iscorrect.(错)
2)Thedeclaration:
floatf=f+1.1;iscorrect.(错)
3)Whichofthefollowingistheillegalvariablenames?
(D)
A.LadB.n_10C._567D.g#k
转义字符的应用
1)Supposedeclaration:
charc=’\010’;thenthecountofcharacterinvariablecis___1___.
当变量成为计数器和累加器的时候如何初始化
1)Whenweusesumasanaccumulatingoracounting,weshouldfirstinitializedsumto___0______
作为计数器或累加器的变量在使用之前必须初始化为0,防止原来的垃圾数据影响程序的执行。
4.运算符和表达式
运算符:
自增自减运算符,逗号运算符
算术运算符,逗号运算符,
1)Theexpression"(x=y=w=0,y=5+w,x=y)"iswrong.。
(错)
这是一个逗号运算符的题目,逗号运算符具有最低优先级,先计算,后取值。
2)Theresultofexpression:
x=(i=4,j=16,k=32)is32.(对)
3)Theoperandofoperator++/--canbevariablesorconstants.(错)
自增自减运算符只能用于变量不能用于常量。
4)The%operatorcannotbeappliedtoafloatordouble.(对)
%是取余数的运算符,只能用在整型数中。
运算符的优先级和结合性
Assignmentoperatorhasthelowestprecedenceandaleft-to-rightassociativity.(错)
5.格式化输入与输出
1)Writetheresultoffollowingprogram5.2
main(){floata=5.23;printf(“%6.1f”,a);}
2)Supposecodesegment:
intk1,k2,k3,k4;
scanf(“%d%d”,&k1,&k2);
scanf(“%d,%d”,&k3,&k4);
ifwewantk1,k3getvalue10,
andk2,k4getvalue20,
thentheaccurateinputis___102010,20___.
6.注释及语句
C语言中,没有输入输出语句,只有输入输出函数.
main函数的位置
注释.不影响程序运行,编译时也不能发现其中的错误,注释的写法
1)Commentshavenoeffecttotheperformanceofprogram.(对)
2)Clanguagehasnoinput/outputstatement,justinput/outputfunctionsinstead.(对)
3)Writetheresultoffollowingprogram:
(___11___)main(){intx=021;printf(“%x”,x);}
4)Writetheresultoffollowingprogram:
(___3.140000___)main(){floata=3.14;printf(“%f”,a);}
5)InC,commentsmustbeginwith__/*___andendwith_*/____.
6)ACprogram,whateveritssize,consistsof_functions___andvariables.
7)Anexpressionbecomesastatementwhenitisfollowedbya__;____.
8)Valueoftheassignmentexpression:
c=25is__25______
9)sum=sum+3canbewrittenas__sum+=3______
第二章选择结构
主要内容:
1.关系运算
2.选择语句的使用
3.文件包含命令
1.关系运算
关系运算符
<>==>=<=!
=
1)(x<=y<=z)isClanguageexpressionforrelationshipx≤y≤z.(错)
2)Valueoftheexpression‘a’+1==’b’isfalse.(错)
逻辑运算符
!
&&||
1)(x<=y)&&(x<=z)isClanguageexpressionforrelationshipx≤y≤z.(对)
2)Whenais1andbis0,thevalueofa||bistrue.(对)
3)Thedeclarationis:
intx=2,y=4,z=5;
whichofthefollowingexpressionequalsto0?
(D)
A.x&&yBx<=yCx||y+z&&y-zD!
z
4)Inthefollowingoperators,whichonehasthelowestprecedence?
(C)D
A.*B.&C.||D.=[==]
关系表达式
1)Theresultofexpression:
3&&5||1%2is1.(对)
2)(ch>='A')&(ch<='Z')cantellyouwheathervariablechisuppercase.(错)
3)Whichonecanexpressx≥y≥zcorrectly?
(A)
A(x>=y)&&(y>=z)B(x>=y)and(y>=z)Cx>=y>=zD(x>=Y)&&(Y>=z)
4)Thecorrectexpressonfor1≤x≤10and100≤y≤200is_(1<=x&&x<=10)&&(100<=y&&y<=200)_.
5)Havingknowing:
intx=3,y=4,z=5;amongfollowingexpressions,whosevaluearenot0(ABC)
A.'x'&&'y'B.x<=yC.x||y+z&&y-zD.!
((xz||1)
条件运算符及条件表达式
1)Supposedeclaration:
w=1,x=2,y=3,z=4;thenthevalueofw>x?
w:
y>z?
y:
zis4.(对)
2)Afterrunningfollowingblockofprogram,valueofvariablemis(D)
intw=1,x=2,y=3,z=4,m;
m=(ww:
x;m=(mm:
y;m=(mm:
z;
A.4B3C2D1
3)Supposethefollowingcodesegment:
intw=1,x=2,y=3,z=4,m;m=(ww:
x;m=(mm:
y;m=(mm:
z;finallythevalueofmis___1___.
2.if语句
1)Thestatement:
if(x=y)&&(x!
=0)x+y;iscorrect.(错)
2)Thestatementif(x3)Thestatementif(n)meansifnisnot0.(对)
4)Theresultofthefollowingprogramis(C)
main()
{inti=1,j=1,k=2;
if((j++||k++)&&i++)
printf("%d,%d,%d\n",i,j,k);
}
A.1,1,2B2,2,1C2,2,2D2,2,3
5)Readthefollowingprogramandtheresultofit.Filltheblanks.main(){int_a=1_____,b=2,c=3;if(c=a)printf(“%d\n”,c);elseprintf(“%d\n”,b);}result:
1(?
)3
5)Ifweusethefollowingfourexpressionsascontrolexpressionforifstatement,whichonehasdifferentmeaningstoothers?
(D)
A.k%2B.k%2==1C.(k%2)!
=0D.k%2==0
6)main(){inta=100,x=10,y=20,ok1=5,ok2=1;if(x=10)if(!
ok1)a=1;elseif(ok2)a=10;}finallythevalueofais__10____.
7)Thepieceofprogramwilloutputwhetherayearisaleapyearornot.Leapyear:
coulddividedby4butcouldnotdividedby100;
(2)coulddividedby400.
main()
{intyear,leap;
printf(“inputyear:
”);
scanf(“%d”,&year);
if(year%400==0)__leap=1_____;
elseif((year%4==0)&&(year%100!
=0))leap=1;
elseleap=0;
if(leap!
=_1___)printf(“%disaleapyear\n”,year);
elseprintf(“%disnotaleapyear\n”,year);
}
8)Havingknown:
inta=1,b=2,c=3,x;,afterrunningfollowingblockofprogram,,thesatementswhichenablevalueofxtobe3are_AD____。
A.if(c3)x=3;elseif(a<2)x=2;elsex=1;
C.if(a<3)x=1;if(a<2)x=2;if(a<1)x=3;D.if(a
9)Clanguagerequestinembededifstatement,theuseofelsemustbe与离它最近的上方的一个if匹配。
3.switch语句
1)Theswitchstatementisamulti-waydecision.(对)
2)Inthestatementswitch(expression),expressioncanbeanytype.(错)
3)Theresultofthefollowingprogramis(C)
main()
{inti=0;
if(i<=5)
{i++;
switch(i%5)
{case0:
printf(“*”);break;
case1:
printf(“#”);break;
default:
printf(“\n”);
case2:
printf(“&”);}}}
A.#&B#*C#D&
4)main(){intx=1,y=0,a=0,b=0;switch(x){case1:
switch(y){case0:
a++;break;case1:
b++;break;}case2:
a++;b++;break;case3:
a++;b++;}printf("a=%d,b=%d",a,b);}Therunningresultis_a=2,b=1_____.
第三章循环结构
主要内容:
1.for循环
1)Thestatement:
for(a=0,b=1,i=0;i<=200;i++)iscorrect.(对)
2)Theresultofthefollowingblockofprogramis:
(D)for(x=3;x<6;x++){if(x%2!
=0)printf(“**%d”,x);elseprintf(“##%d\n”,x);}
A.**3##4**5B##3**4##5C##3**4##5D**3##4
**5
3)Writetheresultoffollowingprogram:
(__23____)main(){intcount;count=2;for(;count<=20;count+=3);printf("%d",count);}
4)Writetheresultofthefollowingprogram:
Themaxvalueis27#includeintfindMax(int[],int);intmain(){intnums[5]={2,18,1,27,16};printf("Themaxvalueis%d",findMax(nums,5));}intfindMax(intvals[],intnumels){inti,max=vals[0];for(i=1;i2.while循环
1)Supposecodesegment:
intk=10;while(k=0)k=k-1;thentheloopwillexecute10times.(错)
2)Readthefollowingprogram:
inti=4,iArr[5];while(i>=0){iArr[i]=100;i--;}Thisprogramsegmentcannotbereplacedwith(D)
A.inti=4,iArr[5];while(i>=0){iArr[i--]=100;}
B.inti=4,iArr[5];while(i>=0){iArr[i]=100;i-=1;}
C.inti=4,iArr[5];for(;i>=0;i--){iArr[i]=100;}
D.inti=4,iArr[5];for(i=0;i>=0;i++){iArr[i]=100;}
3)Writetheresultoffollowingprogram:
(__21____)main(){intnum=0;while(num<=20)num++;printf("%d",num);}
3.do…while循环
1)Indo-while,theloopisexecutedatlestonce.(对)
2)Theresultofthefollowingprogramis:
(A)
inta=1,b=1;do{a++;b--;}while(b<0);printf(“a=%d,b=%d\n”,a,b);
A.a=2,b=0Ba=1,b=1Ca=3,b=-1Da=2,b=1
4.空语句的使用
1)Anullstatementhasnoeffecttotheperformanceofprogram.(错)
第四章函数
主要内容:
1.函数的定义
2.函数参数和函数的值
3.函数调用
4.数组作为函数参数
5.局部变量和全部变量
6.动态存储变量和静态存储变量
7.宏定义
1.函数的定义
1)Whichofthefollowingfunctiondefinitionsiscorrect?
(A)
A.doublefun(intx,inty)Bdoublefun(intx;inty)
C.doublefun(intx,y)Ddoublefun(intx,y;)
2)Whichofthefollowingstatementsiscorrect?
(A)
A.Cprogramsgenerallyconsistofmanysmallfunctions.
B.Functi