第九章测试
1.可以用typedef将已存在的类型用一个新的名字来代表
A:错 B:对
答案:B
2.用typedef定义新的类型名后,原有类型名仍有效
A:错 B:对 3.函数可以返回指向结构体变量的指针
A:错 B:对 4.函数的返回值类型不能是结构体类型,只能是是简单类型
A:对 B:错 5.设有定义:
  struct complex
  { int real,unreal;}data1={1,8},data2;
  则data2=(2,6);是正确的。

A:错 B:对 6.以下结构体类型说明和变量定义中正确的是( )。
7.

有以下程序:

#include<stdio.h>

#include<string.h>

struct A

{  int a; 

   char b[10]; 

   double c;

};

void f(struct A t);

void main()

{  struct A a={1001,"ZhangDa",1098.0};    

   f(a);     

   printf("%d,%s,%6.1f\n", a.a, a.b, a.c);

}

void f(struct A t)

{  t.a=1002;     

   strcpy(t.b,"ChangRong");     

   t.c=1202.0;

}

程序运行后的输出结果是(  )。



A:

1002,ChangRong,1202.0

B:

1001,ZhangDa,1098.0

C:

1001, ChangRong,1098.0

D:

1002, ZhangDa,1202.0

8.

有以下程序段:     

struct st     

{ int x;int *y;}*pt;     

int a[]={1,2},b[]={3,4};     

struct st c[2]={10,a,20,b};     

pt=c;

以下选项中表达式的值为11的是(  )。



A:

pt->x

B:

*pt->y

C:

++pt->x

D:

(pt++)->x

9.

有以下程序:    

#include<stdio.h>    

struct S{int n;int a[20];};    

void f(int *a, int n)    

{  int i;        

   for(i=0;i<n-1;i++)              

     a[i]+=i;    

}    

main()    

{ int i;            

  struct S s={10,{2,3,1,6,8,7,5,4,10,9}}; 

  f(s.a,s.n);        

  for(i=0; i<s.n; i++)             

    printf("%d,", s.a[i]);    

}

程序运行后的输出结果是(  )。



A:

3,4,2,7,9,8,6,5,11,10,

B:

1,2,3,6,8,7,5,4,10,9,

C:

2,3,1,6,8,7,5,4,10,9,

D:

2,4,3,9,12,12,11,11,18,9,

10.

有以下程序:

#include<stdio.h>

#include<string.h>

typedef struct 

{char name[9]; char sex; float score[2]; }STU;

void f(STU a)

{  STU b={"Zhao",'m',85.0,90.0};     

   int i;    

   strcpy(a.name,b.name);    

   a.sex=b.sex;    

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

     a.score[i]=b.score[i];

}

void main()

{ STU c={"Qian",'f',95.0,92.0};   

  f(c);        

  printf("%s,%c,%2.0f,%2.0f\n", c.name, c.sex, c.score[0], c.score[1]);

}

程序的运行结果是(  )。



A:

Zhao,f,95,92

B:

Qian,m,85,90

C:

Zhao,m,85,90

D:

Qian,f,95,92

11.下面结构体的定义语句中,错误的是(  )。
A:struct {int x;int y;int z;} a; B:struct ord {int x;int y;int z;}; struct ord a; C:struct ord {int x;int y;int z;} a; D:struct ord {int x;int y;int z;} struct ord a; 12.

设有以下程序段

struct MP3 

{char name[20];  char color;   float price;}std, *ptr;

ptr=&std;

若要引用结构体变量std中的color成员,写法错误的是(  )。



A:

std.color

B:

(*ptr) .color

C:

ptr-> color

D:

std-> color

13.

有以下函数

#include<stdio.h>

struct stu

{int mun; char name[10]; int age;};

viod fun(struct stu *p)

{ printf(“%s\n”,p->name); }

void main()

{ struct stu x[3]={{01,”zhang”,20},{02,”wang”,19},{03,”zhao”,18}};

  fun(x+2);

}

程序运行输出结果是(  )。



A:

19

B:

zhao

C:

wang

D:

zhang

14.

#include <stdio.h>

  struct ord

  { int x,y;}dt[2]={1,2,3,4};

  main()

  {struct ord *p=dt;

   printf("%d,",(++ p)->x);

 printf("%d\n",++(p->y));}

  程序运行后的输出结果是(   )。



A:

1,2

B:

3,4

C:

3,5

D:

2,3

15.

有如下程序段:

#include <stdio.h> 

void main( )

{ struct a{int x;int y;}num[2]={{20,5},{6,7}};

printf( "%d\n", num[0].x/num[0].y*num[1].y );

}

执行后的输出结果是(   )。



A:

28

B:

5

C:

20

D:

0

16.

有以下定义和语句

  struct workers

  { int num;

      char name[20];

      char c;

    struct

     {int day; int month; int year;}s;

  };

  struct workers w,*pw;

  pw=&w;

  能给w中year成员赋1980的语句是(   )。



A:

w.year=1980;

B:

pw->year=1980;

C:

*pw.year=198O;

D:

w.s.year=1980;

17.

有以下程序

#include<stdio.h>

#include<string.h>

struct A

{ int a; char b[10]; double c;};

struct A f(struct A t);

void main()

{ struct A a={1001,”ZhangDa”,1098.0};

  a=f(a);

  printf(“%d,%s,%6.1f\n”,a.a ,a.b, a.c);

}

struct A f(struct A t)

{ t.a=1002; 

  strcpy(t.b,”ChangRong”); 

  t.c=1202.0;

  return t;

}

程序运行后的输出结果是(   )。



A:

1002,ZhangDa,1202.0

B:

1001,ChangRong,1098.0

C:

1001,ZhangDa,1098.0

D:

1002,ChangRong,1202.0

18.

有以下程序

#include<stdio.h>

struct st

{ int x, y;}data[2]={l,10,2,20};

void main()

{ struct st *p=data;

  printf("%d,", p->y); 

  printf("%d\n",(++p)->x);

}

程序的运行结果是( )。



A:

20,2

B:

10,1

C:

10,2

D:

20,1

19.

有以下程序

#include<stdio.h>

struct tt 

{int x;struct tt *y;} *p;

struct tt a[4]={20,a+1,15,a+2,30,a+3,17,a};

void main()

{ int i;

   p=a;

   for(i=1;i<=2;i++) 

     {printf("%d,",p->x); p=p->y;}

}

程序的运行结果是(  )。



A:

15,30

B:

30,17

C:

20,30

D:

20,15

20.

设有以下定义
union data
{ int d1; float d2; }demo;
则下面叙述中错误的是


A:

变量demo与成员d2所占的内存字节数相同

B:

变量demo和各成员的地址相同

C:

若给demo.d1赋99后, demo.d2中的值是99.0

D:

变量demo中各成员的地址相同

温馨提示支付 ¥4.99 元后可查看付费内容,请先翻页预览!
点赞(125) dxwkbang
返回
顶部