二级c串讲--简化版

上传人:第*** 文档编号:50960033 上传时间:2018-08-11 格式:PPT 页数:51 大小:533.50KB
返回 下载 相关 举报
二级c串讲--简化版_第1页
第1页 / 共51页
二级c串讲--简化版_第2页
第2页 / 共51页
二级c串讲--简化版_第3页
第3页 / 共51页
二级c串讲--简化版_第4页
第4页 / 共51页
二级c串讲--简化版_第5页
第5页 / 共51页
点击查看更多>>
资源描述

《二级c串讲--简化版》由会员分享,可在线阅读,更多相关《二级c串讲--简化版(51页珍藏版)》请在金锄头文库上搜索。

1、国家二级C串讲第一章 C语言程序初步知识点: 1 、程序的构成,MAIN函数和其他函数。函数 的开始和结束标志。 2、源程序的书写格式:第一分册第2页 3、标识符 (1)标识符的定义:第一分册第3页 (2)注意标识符和自定义标识符的区别4、常量的类型注意:各种常量的表示方法5、变量的定义 6、表达式计算第二章 顺序结构知识点: 1、语句的概念:表达式语句:i=2;空语句: ;复合语句: 2、printf函数 3、scanf函数重点是格式控制符格式控制符具体含义见第一分册第19页和23页第三章 选择结构知识点: 1、关系运算 = main() int x=1,y=0,a=0,b=0;switch

2、(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=%dn“,a,b); 程序的运行结果是( ) A)a=1,b=0 B)a=2,b=2 C)a=1,b=1 D) a=2,b=1 答案:Dbreak;第四章 循环结构知识点: 1、三种循环结构while(条件)do while(条件) for(.) 2、break和continue break:中断语句 continue:短路语句例:有以下程序 #include main() int

3、x=8;for( ; x0; x-) if(x%3) printf(“%d,“,x-); continue; printf(“%d,“,-x); 程序的运行结果是( ) A)7,4,2 B)8,7,5,2, C)9,7,6,4 D)8,5,4,2 答案:D 分析:continue称为短路语句,continue以下的循 环体内的语句将被跳过不执行。直接进入下一轮 循环。例:有以下程序 # include main() int i=5;do if (i%3=1)if (i%5=2) printf(“*%d“, i); break;i+; while(i!=0);printf(“n“); 程序的运行

4、结果是( )。 A)*7 B)*3*5 C)*5 D)*2*6 答案:A例:以下程序的输出结果是 。 #include main() int i,j,sum;for(i=3;i=1;i-) sum=0;for(j=1;j2!1答案:D 分析:检查数组下标有没有超出范围 关系运算,逻辑运算的值以真为1,假为0例:有以下程序 #include main( ) int s12=1,2,3,4,4,3,2,1,1,1,2,3,c5=0,i;for(i=0;i main() int x44,n=0,i,j; for(j=0;j=j; ) n+;xij= ;for(i=0;i main() int j,

5、a =1,3,5,7,9,11,13,15,*p=a+5;for(j=3; j; j-) switch(j) case 1:case 2: printf(“%d“,*p+); break;case 3: printf(“%d“,*(-p); 答案:9911分析:程序执行前的初始状态,然后根据程序调整各个变量的值 数组 a数组元素的 值 a01 a13 a25 a37 a49 pa511 a613 a715变量j的值3例:有以下程序 #include main( ) int a =1,2,3,4,y,*p=-p; y=*p; printf(“y=%dn“,y); 程序的运行结果是( ) A)y=

6、0 B)y=1 C)y=2 D)y=3 答案:D例:以下程序的定义语句中,x1的初值是 , 程序运行后输出的内容是 。 #include main() int x =1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,*p4,i;for(i=0;i void swap(int *a,int *b) int *t;t=a;a=b;b=t; main() int i=3,j=5,*p=swap(p,q); printf(“%d %dn“,*p,*q); 答案:3 5void swap(int *a,int *b) int t;t=*a;*a=*b;*b=t; 例:以下程序

7、的输出结果是 。 #include void fun(int x) if(x/20) fun(x/2);printf(“%d“,x); main() fun(3); printf(“n“); 答案:13分析:调用fun(1)输出1,然后回到fun(3)再输出3fun(3) x=3 void fun(int x) if(x/20) fun(x/2);printf(“%d“,x); fun(1) x=1 void fun(int x) if(x/20) fun(x/2);printf(“%d“,x); 例:有以下程序 #include int fun(int a,int b) if(b=0) re

8、turn a;else return(fun(-a,-b); main() printf(“%dn“, fun(4,2); 程序的运行结果是( )。 A)1 B)2 C)3 D)4答案:B分析:fun(4,2) a=4 b=2 int fun(int a,int b) if(b=0) return a;else return(fun(-a,-b); 返回主函数fun(3,1) a=3 b=1 int fun(int a,int b) if(b=0) return a;else return(fun(-a,-b); fun(2,0) a=2 b=0 int fun(int a,int b) if

9、(b=0) return a;else return(fun(-a,-b); 例:有以下程序 #include void fun(int *s,int n1,int n2) int i,j,t;i=n1; j=n2;while(i #include int fun(int n) int *p;p=(int*)malloc(sizeof(int);*p=n; return *p; main() int a;a = fun(10); printf(“%dn“, a+fun(10); 程序的运行结果是( )。 A)0 B)10 C)20 D)出错 答案:C例:有以下程序 #include int f

10、un(int (*s)4,int n, int k) int m, i; m=s0k;for(i=1; im) m=sik;return m; main() int a44=1,2,3,4,11,12,13,14,2l,22,23,24,31,32,33,34 ;printf(“%dn“, fun(a,4,0); 程序的运行结果是( )。 A)4 B)34 C)31 D)32 答案:C(13)以下程序的功能是:通过函数func输入字符 并统计输入字符的个数。输入时用字符作为输 入结束标志。请填空。 #include long ; /* 函数说明语句 */ main() long n; n=fu

11、nc(); printf(“n=%ldn“,n); long func() long m;for( m=0; getchar()!=; );retum m; 答案:func() , m+第九章 字符串知识点: 1、字符串的表示:如“how do you do” 2、字符串的存诸形式: 如: “spels” spels03、字符串与数组 char str10=s,p,e,l,s; char str =s,p,e,l,s,0; char str =s,p,e,l,s;spels00000 spels0spels3、字符串与数组 char str10=s,p,e,l,s;char str =s,p,

12、e,l,s,0; char str =“spels”;char str =s,p,e,l,s;4、字符串与指针 char *p=“spels”; 5、字符串函数 char str1100,str2100; puts(str1); gets(str1); strcpy(str1,str2); len=strlen(str2); strcat(str1,str2); i=strcmp(str1,str2);例:有以下程序 #include #include void fun(char *s ,int n) char *t; int i,j;for(i=0;istrlen(sj) t=si;si=s

13、j;sj=t; main( ) char *ss =“bcc“,“bbcc“,“xy“,“aaaacc“,“aabcc“;fun(ss,5); printf(“%s,%sn“,ss0,ss4); 程序的运行结果是( ) A)xy,aaaacc B)aaaacc,xy C)bcc,aabcc D) aabcc,bcc 答案:A 分析:函数fun是一个将字符串按长度排序的程序第十章 编译预处理 位运算知识点: 1、文件包含 #include “文件名” 如:#include “stdio.h” 2、宏替换 #define 宏名 替换文本例: #define MUL(a,b) (a)*(b)#define IMUL(a,b) (a*b) m=MUL(10-5,5+1)/2 等价于: m=(10-5)*(5+1)/2IMUL(10-5,5+1)/2 等价于: m=(10-5*5+1)/23、位运算 位与:return(t +=x); main() int s,i;for(i=1;i #include typedef struct char name9; char sex; float score2; STU; void f(STU a

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号