预处理和动态存储分配

上传人:daj****de2 文档编号:200104162 上传时间:2023-04-14 格式:DOCX 页数:16 大小:19.21KB
返回 下载 相关 举报
预处理和动态存储分配_第1页
第1页 / 共16页
预处理和动态存储分配_第2页
第2页 / 共16页
预处理和动态存储分配_第3页
第3页 / 共16页
点击查看更多>>
资源描述
、选择题(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() char a7=a00a00”;int i,j;i=sizeof(a); j=strlen(a);printf(%d %dn”,i,j);程序运行后的输出结果是A)2 2C) 72D) 6 2(4) 以下叙述中正确的是A) 预处理命令行必须位于源文件的开头B) 在源文件的一行上可以有多条预处理命令C) 宏名必须用大写字母表示D) 宏替换不占用程序的运行时间有以下程序main()( char a=”abcdefg”,b10=”abcdefg”;printf(d %dn”,sizeof(A) ,sizeof(B);执行后输出结果是A) 7 7 B) 8 8 C) 8 10 D) 10 10(6)有以下程序#define f(x) x*xmain( )( int i;i=f(4+4)/f(2+2);printf(dn”,i);执行后输出结果是A) 28 B) 22 C) 16 D) 4#include #define F(X,Y) (X)*(Y)main ()( int a=3, b=4;printf(%dn”, F(a+,b+);程序运行后的输出结果是A) 12 B) 15 C) 16 D) 20(8)有以下程序main() char s=n123;printf(%d,%dn”,strlen(s),sizeof(s);执行后输出结果是A)赋初值的字符串有错B) 6,7 C) 5,6 D) 6,6有以下程序main(int arge,char *argv) int n,i=0;while(arv1i!=0 n=fun(); i+;printf(%dn”,n*argc);int fun() static int s=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);printH“d,%db”i,j);程序运行后的输出结果是A)9,9 B)8,9C)1,8 D)9,8(11) 程序中头文件typel.h的内容是:#define N 5#define M1 N*3程序如下:#define “typel.h”#define M2 N*2main()( int i;i=M1+M2; printH“dn”,i);程序编译后运行的输出结果是:A) 10 B) 20 C) 25 D) 30#include main()( char *p,*q;p=(char*)malloc(sizeof(char)*20); q=p;scanf(s%s,p,q); printf(s%sn,p,q);若从键盘输入:abc def,则输出结果是:A) def def 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= “hello0t”;printf(%d %d n”,strlen(st),sizeof(st);A) 9 9 B) 5 20 C) 13 20 D) 20 20(15) 以下程序的输出结果是amovep(int p, int (a)3,int n) int i, j;for( i=0;i;i+)for(j=0;jn;j+) *p=aij;p+; int *p,a33=1,3,5,2,4,6;p=(int *)malloc(100);amovep(p,a,3);printf(“%d %d n”,p2,p5);ftee(p);A) 56 B) 25 C) 34 D)程序错误(16) 以下程序的输出结果是#define M(x,y,z) x*y+zmain() 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*Xmain() int a=16, k=2, m=1;a/=SQR(k+m)/SQR(k+m);printf(dn,a);(18) 若定义了以下函数:void f()(*p=(double *)malloc( 10*sizeof( double);p是该函数的形参,要求通过p把动态分配存储单元的地址传回主调函数,则形参p的正确定义应当是A) double *p B) float *p C) double *p D) float *p(19) 有如下程序#defineN2#defineMN+1#define NUM 2*M+1#main()( int i;for(i=1i=NUMi+)printf(“%d n”,i)该程序中的for循环执行的次数是A) 5 B) 6 C) 7 D) 8(20) 下列程序执行后的输出结果是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 D) 5#includeint 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*xmain( ) int a=6, b=2, c;c=f(a) / f(b);printf(%d n, c);(24) 以下程序运行后,输出结果是A) 49.5 B) 9.5 C) 22.0 D) 45.0#include#define PT 5.5( int a=1,b=2;printf(%4.1fn”,S(a+b);(25) 以下程序运行后,输出结果是A) 1 B) 7 C) 9 D) 11fut(int *s, int p3) *s=p11;main() int a23=1,3,5,7,9,11, *p;p=(int *) malloc(sizeof(int);fut(&p,a);printf(%dn”,*P);(26) 设有以下宏定义:#define N 3#define Y(n) ( (N+1)*n)则执行语句:z=2 * (N+Y(5+1);后,z的值为A)出错 B) 42 C) 48 D) 54(27) 若有说明,double *p,a;则能通过scanf语句正确给输入项读入数据的程序段是A)*p=&a; scanf(%lf”,p); B)p=(double *)malloc(8);scanf(%f”,p);C) p=&a;scanf(%lf”,a); D)p=&a; scanf(%le”,p);(28) 执行下面的程序后,a的值是#define SQR(X) X*X( int a=10,k=2,m=1;a/=SQR(k+m)/SQR(k+m);printf(%dn”,a); A) 10 B) 1 C) 9 D) 0(29) 以下程序的输出结果是fut (int*s,int p2 3)*s=p11;main( ) int a23=1,3,5,7,9,11,*p;p=(int*)malloc(sizeof(int);fut(&p,a);primtf(%dn”,*p); A) 1 B) 7 C) 9 D) 11(30) 若要用下面的程序片段使指针变量p指向一个存储整型变量的动态存储单元:int *p;p=malloc( sizeof(int);则应填入A) int B) inst * C) (*int) D) (int *)(31) 请读程序:#include#define SUB(X,Y) (X)*Ymain() int a=3, b=4;printf(%d”, SUB(a+, b+);上面程序的输出结果是A) 12 B) 15 C) 16 D) 20(32) 请读程序:#includevoid fun(float *pl, float *p2, float *s)( s=( float * )calloc( 1, sizeof(float);*s=*p1+ *(p2+);main() float a2=1.1, 2.2, b2=10.0, 20.0, *s=a;fun(a, b, s)printf(%fn,*s);上面程序的输出结果是A) 11.100000 B) 12.100000 C) 21.100000 D) 1.100000(33) 在宏定义#define PI 3.14159中,用宏名PI代替一个A)单精度数 B)双精度数C)常量 D)字符串(34) 请选出以下程序段的输出结果#include#define MIN(x,y) (x)(y)? (x):(y)main() int i,j,k;i=10; j=15;k=10*MIN(i,j);printf(%dn”,k);A) 15 B) 100 C) 10 D) 150(35) sizeof(double)是【35 】。A) 一种函数调用 B) 一个双精度型表达式C) 一个整型表达式 D) 一个不合法的表达式(36) 以下for语句构成的循环执行了【36】次。# include # define N 2# define M N+1# define NUM (M+1)*M/2main()( int i , n=0;for ( i=1;i=NUM;i + + );n + + ; printf(%d”,n); printf(n); A) 5 B) 6 C) 8 D) 9(37) 以下程序的输出结果是 【37】。# include# define FUDGE(y) 2.84+y# define PR(a) printf(%d”,(int)(a)# define PRINT1(a) PR(a);putchar(n)main()int x=2; PRINT1(FUDGE(5)*x); A) 11 B) 12 C) 13 D) 15二、填空题:(1)已有定义:double *p;,请写出完整的语句,利用malloc函数使p指向一个双精度 型的动态存储单元【1】。(2 )以下程序运行后的输出结果是【2】.#define S(x) 4*x*x+1 main()int i=6,j=8;printf(%dn”,S(i+j);(3) 以下程序中,for循环体执行的次数是【3】。#define N 2#define M N+1#define K M+1*M/2 main() int i;for(i=1;iK;i+) . (4) 以下程序中给指针p分配三个double型动态内存单元,请填空。# include main ( ) double *p;p=(double *) malloc(【4】);p0=1.5;p1=2.5;p2=3.5;printf(“f%f%fn”,p0,p1,p2)(5) 以下程序的输出结果是【5】。#defint MCRA(m) 2*m#define MCRB(n,m) 2*MCRA(n)+mmain()( int i=2,j=3;printf(%dn,MCRB(j,MCRA (i);(6) 下面程序的运行结果是【6】。#define N 10#define s(x) x*x#define f(x) (x*x)main()( int i1,i2;i1=1000/s(N); i2=1000/f(N);printf(“%d %dn”,i1,i2)(7) 设有如下宏定义#define MYSWAP(z,x,y) z=x; x=y; y=z;以下程序段通过宏调用实现变量a、b内容交换,请填空。float a=5,b=16,c;MYSWAP( 【7】 ,a,b);(8)用以下语句调用库函数malloc,使字符指针st指向具有11个字节的动态存储空间,请填空。st=(char*)【8 】;(9) 以下程序的输出结果是【9】。#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(dn,t)(10) 若要使指针p指向一个double类型的动态存储单元,请填空。p= 10 malloc(sizeof(double);(11) 下面程序的输出是【11】。#define PR(ar) printf(%d”, ar)main() int j, a= 1,3,5,7,9,11,13,15, *p=a+5;for(j=3; j; j-) switch(j) case 1:case 2: PR(*p+); break;case 3: PR(*(-p);答案:一、选择题:1) C 2) C 3) C 4) D 5) C 6) A 7) A 8) C 9) A 10) D11) C 12) A 13) A 14) B 15) A 16) D 17) B 18) C 19) B 20) B21) A 22) D 23) C 24) B 25) C 26) C 27) D 28) B 29) C 30) D31) A 32) D 33) D 34) A 35) C 36) C 37) B 38) 39) 40)二、填空题:(1) p=(double*)malloc(sizeof(double)(2) 81(3) 4(4) 3*sizeof(double)16(6) 1000 10(7) c(8) Malloc (11)或 malloc(sizeof(char)*11)(9) 7(10) (double *)(11) 9911
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸设计 > 毕设全套


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!