编译预处理和动态存储分配及答案.docx

上传人:b****5 文档编号:11799332 上传时间:2023-04-02 格式:DOCX 页数:12 大小:19.56KB
下载 相关 举报
编译预处理和动态存储分配及答案.docx_第1页
第1页 / 共12页
编译预处理和动态存储分配及答案.docx_第2页
第2页 / 共12页
编译预处理和动态存储分配及答案.docx_第3页
第3页 / 共12页
编译预处理和动态存储分配及答案.docx_第4页
第4页 / 共12页
编译预处理和动态存储分配及答案.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

编译预处理和动态存储分配及答案.docx

《编译预处理和动态存储分配及答案.docx》由会员分享,可在线阅读,更多相关《编译预处理和动态存储分配及答案.docx(12页珍藏版)》请在冰豆网上搜索。

编译预处理和动态存储分配及答案.docx

编译预处理和动态存储分配及答案

编译预处理和动态存储分配

一、选择题

(1)有以下程序

 main()

 {char p[]={'a','b','c'},q[]="abc";

  printf("%d %d\n",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,%d\n",i1,i2);

 }

程序运行后的输出结果是

 A)64,28  

 B)4,4   

 C)4,3   

 D)64,64

(3)有以下程序

main()

{  char a[7]="a0\0a0\0";int i,j;

   i=sizeof(a); j=strlen(a);

   printf("%d %d\n",i,j);

}

程序运行后的输出结果是   

 A)2   2

 B)7   6

 C)7   2

 D)6   2

(4)以下叙述中正确的是                 

 A)预处理命令行必须位于源文件的开头

 B)在源文件的一行上可以有多条预处理命令

 C)宏名必须用大写字母表示

 D)宏替换不占用程序的运行时间

(5)有以下程序

main()

{ chara[]=”abcdefg”,b[10]=”abcdefg”;

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

}

执行后输出结果是

 A)7 7   

 B)88   

 C)810  

 D)1010

(6)有以下程序

#define f(x)   x*x

main()

{ inti;

  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("%d\n",F(a++,b++));

}

程序运行后的输出结果是

 A)12         

 B)15           

 C)16          

 D)20

(8)有以下程序

main()

{ char s[]="\n123\\";

 printf("%d,%d\n",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(arv[1][i]!

='\0'

{ n=fun(); i++;}

 printf(%d\n",n*argc);

}

int fun()

{ staticint s=0;

 s+=1;

 return s;

}

假设程序经编译、连接后生成可执行文件exam.exe,若键入以下命令行

exam 123<回车>

则运行结果为

(10)有以下程序

main()

{chara[]={‘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

程序如下:

#define  “type1.h”

#define  M2  N*2

main()

{inti;

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);

若从键盘输入:

abcdef<回车>,则输出结果是:

 A)defdef  

 B)abcdef  

 C)abcd  

 D)dd

(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 st[20]=“hello\0\t\\\”;

printf(%d%d\n”,strlen(st),sizeof(st));

}

 A)99   

 B)520   

 C)1320       

 D)2020

(15)以下程序的输出结果是

amovep(int p,int (a)[3],int n)

{  int  i,j;

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

for(j=0;j

}

main()

{  int   *p,a[3][3]={{1,3,5},{2,4,6}};

p=(int*)malloc(100);

amovep(p,a,3);

printf(“%d%d\n”,p[2],p[5]);free(p);

}

 A)56     

 B)25          

 C)34      

 D)程序错误

(16)以下程序的输出结果是

#define   M(x,y,z)   x*y+z

main()

{  int a=1,b=2,c=3;

printf(“%d\n”,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)若定义了以下函数:

voidf(……)

{……

   *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(“%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()

    {inta=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

   #include 

   int    a[3][3]={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 p[][3])

   { *s=p[1][1];}

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

  }

(24)以下程序运行后,输出结果是

 A)49.5         

 B)9.5           

 C)22.0          

 D)45.0

      #include

      #define     PT      5.5

      #define     S(x)    PT*x*x

     main()

     {  int   a=1,b=2;

         printf("%4.1f\n",S(a+b));

     }

(25)以下程序运行后,输出结果是

 A)1            

 B)7             

 C)9             

 D)11

      fut(int   **s,int p[2][3])

      {  **s=p[1][1];}

      main()

      {  int  a[2][3]={1,3,5,7,9,11}, *p;

          p=(int *)malloc(sizeof(int));

        fut(&p,a);

        printf("%d\n",*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

main()

{inta=10,k=2,m=1;

a/=SQR(k+m)/SQR(k+m);

printf("%d\n",a);    }

 A)10         

 B)1         

 C)9          

 D)0

(29)以下程序的输出结果是

fut(int**s,intp[2][3])

{    **s=p[1][1];   }

main()

{  inta[2][3]={1,3,5,7,9,11},*p;

p=(int*)malloc(sizeof(int));

fut(&p,a);

primtf("%d\n",*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

#defineSUB(X,Y)(X)*Y

main()

{inta=3,b=4;

printf("%d",SUB(a++,b++));

}

上面程序的输出结果是

 A)12           

 B)15            

 C)16            

 D)20

(32)请读程序:

#include

voidfun(float*pl,float*p2,float*s)

{s=(float*)calloc(1,sizeof(float));

*s=*p1+*(p2++);

}

main()

{floata[2]={1.1,2.2},b[2]={10.0,20.0},*s=a;

fun(a,b,s)

printf("%f\n",*s);

}

上面程序的输出结果是

 A)11.100000    

 B)12.100000     

 C)21.100000      

 D)1.100000

(33)在宏定义#definePI3.14159中,用宏名PI代替一个

 A)单精度数     

 B)双精度数      

 C)常量          

 D)字符串

(34)请选出以下程序段的输出结果

#include

#defineMIN(x,y) (x)<(y)?

(x):

(y)

main()

{inti,j,k;

i=10;j=15;

k=10*MIN(i,j);

printf("%d\n",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/2

main()

{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()

{intx=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("%d\n",S(i+j));

}

(3)以下程序中,for循环体执行的次数是【3】 。

#define N2

#define MN+1

#define KM+1*M/2

main()

{inti;

 for(i=1;i

 {...}

 ...

}

(4)以下程序中给指针p分配三个double型动态内存单元,请填空。

#include

main()

{ double*p;

  p=(double*)malloc(【4】); 

  p[0]=1.5;p[1]=2.5;p[2]=3.5;

  printf(“%f%f%f\n”,p[0],p[1],p[2]);

}

(5)以下程序的输出结果是【5】。

#defint  MCRA(m)  2*m

#define  MCRB(n,m) 2*MCRA(n)+m

main()

{ int i=2,j=3;

 printf("%d\n",MCRB(j,MCRA(i)));

}

(6)下面程序的运行结果是【6】。

#define  N  10

#define  s(x) x*x

#define  f(x) (x*x)

main()

{ inti1,i2;

i1=1000/s(N);i2=1000/f(N);

printf(“%d %d\n”,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(“%d\n”,t);

}

(10)若要使指针p指向一个double类型的动态存储单元,请填空。

p= [10] malloc(sizeof(double));  

(11)下面程序的输出是 【11】。

#definePR(ar)printf("%d",ar)

main()

{intj,a[]={1,3,5,7,9,11,13,15},*p=a+5;

for(j=3;j;j--)

{switch(j)

{case1:

case2:

PR(*p++);break;

case3:

PR(*(--p));}

}

}

 

答案:

一、选择题:

01) C  02) C  03) C  04) D  05) C 

06) A  07) A  08) C  09) A  10) D

11) C  12) A  13) A  14) B  15) A 

16) D  17) B  18) C  19) B  20) B

21) A  22) D  23) C  24) B  25) C 

26) C  27) D  28) B  29) C  30) D

31) A  32) D  33) D  34) A  35) C 

36) C  37) B 

二、填空题:

(1)p=(double*)malloc(sizeof(double))

(2)81

(3)4

(4)3*sizeof(double)

(5)16

(6)1000 10

(7)c

(8)Malloc(11)或malloc(sizeof(char)*11)

(9)7

(10)(double*)

(11)9911

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 外语学习 > 韩语学习

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1