2022年编译预处理和动态存储分配及答案 .pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年编译预处理和动态存储分配及答案 .pdf》由会员分享,可在线阅读,更多相关《2022年编译预处理和动态存储分配及答案 .pdf(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、学而不思则惘,思而不学则殆编译预处理和动态存储分配一、选择题(1)有以下程序main() char p=a, b, c, q=abc; printf(%d %dn, sizeof(p),sizeof(q); ; 程序运行后的输出结果是A)4 4 B)3 3 C)3 4 D)4 3 (2)有以下程序# define f(x) (x*x) main() int i1, i2; i1=f(8)/f(4) ; i2=f(4+4)/f(2+2) ; printf(%d, %dn,i1,i2); 程序运行后的输出结果是A)64, 28 B)4, 4 C)4, 3 D)64, 64 (3)有以下程序main
2、() char a7=a00a00;int i,j; i=sizeof(a); j=strlen(a); printf(%d %dn,i,j); 程序运行后的输出结果是A)2 2 B)7 6 C)7 2 D)6 2 (4)以下叙述中正确的是A)预处理命令行必须位于源文件的开头精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 1 页,共 14 页学而不思则惘,思而不学则殆B)在源文件的一行上可以有多条预处理命令C)宏名必须用大写字母表示D)宏替换不占用程序的运行时间(5) 有以下程序main( ) char a=”abcdefg”,b10= ”abcd
3、efg”;printf(“%dn”,sizeof(A) ,sizeof(B) ); 执行后输出结果是A) 7 7 B) 8 8 C) 8 10 D) 10 10 (6) 有以下程序#define f(x) x*x main( ) int i; i=f(4+4)/f(2+2); printf(“%d n”,i); 执行后输出结果是A) 28 B) 22 C) 16 D) 4 (7) 有以下程序#include #define F(X,Y) (X)*(Y) main () int a=3, b=4; printf(%dn, F(a+,b+); 程序运行后的输出结果是A) 12 B) 15 C) 1
4、6 D) 20 (8) 有以下程序精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 2 页,共 14 页学而不思则惘,思而不学则殆main() char s=n123; printf(%d,%dn,strlen(s),sizeof(s); 执行后输出结果是A) 赋初值的字符串有错B) 6,7 C) 5,6 D) 6,6 (9) 有以下程序main(int arge,char *argv) int n,i=0; while(arv1i!=0 n=fun(); i+; printf(%dn,n*argc); int fun() static int s=
5、0; s+=1; return s; 假设程序经编译、连接后生成可执行文件exam.exe, 若键入以下命令行exam 123 则运行结果为(10) 有以下程序main() char a =a,b,c,d, e, f, g,h,0; int i,j; i=sizeof(a); j=strlen(a); printf(“%d,%d b”i,j); 程序运行后的输出结果是A)9,9 B)8,9 C)1,8 D)9,8 (11) 程序中头文件typel.h 的内容是:#define N 5 #define M1 N*3 程序如下:精选学习资料 - - - - - - - - - 名师归纳总结 - -
6、 - - - - -第 3 页,共 14 页学而不思则惘,思而不学则殆#define “type1.h ”#define M2 N*2 main() int i; i=M1+M2; printf(“%d n”,i); 程序编译后运行的输出结果是:A) 10 B) 20 C) 25 D) 30 (12) 有以下程序#include main() char *p,*q; p=(char*)malloc(sizeof(char)*20); q=p; scanf( “%s%s ”,p,q);printf(“%s%s n”,p,q); 若从键盘输入: abc def,则输出结果是:A) def def
7、B) abc def C) abc d D) d d (13) 若指针 p 已正确定义,要使p 指向两个连续的整型动态存储单元,不正确的语句是A) p=2*(int*)malloc(sizeof(int); B) p=(int*)malloc(2*sizeof(int); C) p=(int*)malloc(2*2); D) p=(int*)calloc(2,sizeof(int); (14) 以下程序的输出结果是main() char st20= “hello”;n”,strlen(st),sizeof(st); A) 9 9 B) 5 20 C) 13 20 D) 20 20 (15) 以
8、下程序的输出结果是精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 4 页,共 14 页学而不思则惘,思而不学则殆amovep(int p, int (a)3,int n) int i, j; for( i=0;i;i+) for(j=0;jn;j+) *p=aij;p+; main() int *p,a33=1,3,5,2,4,6; p=(int *)malloc(100); amovep(p,a,3); printf(“%d %d n”,p2,p5);free(p); A) 56 B) 25 C) 34 D) 程序错误(16) 以下程序的输出结果
9、是#define M(x,y,z) x*y+z main() int a=1,b=2, c=3; printf(“%dn ”, M(a+b,b+c, c+a); A) 19 B) 17 C) 15 D) 12 (17) 以下程序的输出结果是A) 16 B) 2 C) 9 D) 1 #define SQR(X) X*X main() int a=16, k=2, m=1; a/=SQR(k+m)/SQR(k+m); printf(“d n”,a); (18) 若定义了以下函数:void f()精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 5 页,共
10、 14 页学而不思则惘,思而不学则殆 *p=(double *)malloc( 10*sizeof( double); p 是该函数的形参,要求通过p 把动态分配存储单元的地址传回主调函数,则形参p 的正确定义应当是A) double *p B) float *p C) double *p D) float *p (19) 有如下程序#define N 2 #define M N+1 #define NUM 2*M+1 #main() int i; for(i=1;i=NUM;i+)printf(“%dn”,i); 该程序中的 for循环执行的次数是A) 5 B) 6 C) 7 D) 8 (2
11、0) 下列程序执行后的输出结果是A) 6 B) 8 C) 10 D) 12 #define MA(x) x*(x-1) main() int a=1,b=2; printf(%d n,MA(1+a+b); (21) 若有说明: long *p ,a;则不能通过scanf 语句正确给输入项读入数据的程序段是A) *p=&a ; scanf(%ld,p);B) p=(long *)malloc(8); scanf(%ld,p) ;C) scanf(%ld,p=&a);D) scanf(%ld,&a) ;(22) 以下程序的输出结果是A) 1 B) 4 C) 7 精选学习资料 - - - - - -
12、 - - - 名师归纳总结 - - - - - - -第 6 页,共 14 页学而不思则惘,思而不学则殆D) 5 #include int a33=1,2,3,4,5,6,7,8,9, ,*p ; main( ) p=(int*)malloc(sizeof(int); f(p ,a); printf(%d n,*p) ; f(int *s, int p3) *s=p11; (23) 以下程序的输出结果是A) 9 B) 6 C) 36 D) 18 #define f(x) x*x main( ) int a=6 ,b=2,c; c=f(a) / f(b); printf(%d n,c) ; (2
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年编译预处理和动态存储分配及答案 2022 编译 预处理 动态 存储 分配 答案
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内