admin 管理员组

文章数量: 1086019


2024年5月21日发(作者:mysql怎么更改密码)

9.3.1 选择题选择题

2. 有以下程序输出结果是( )。

#include

struct stu

{

int num;

char name[10];

int age;

};

void fun(struct stu *p)

{

printf("%sn",(*p).name);

}

main()

{

struct stu students[3]= {{9801,"Zhang",20},{9802,"Wang",19},{9803,"Zhao",18}};

fun(students+2);

}

D.18

4. 设有如下定义:

struct sk

{

int a;

float b;

} data,*p;

若有p=&data;则对data中的a 域的正确引用是( )。

A

6.根据下面的定义,能打出字母M的语句是( )。

struct person

{

char name[9];

int age;

}

struct person class[10]={ 〞John〞,17, 〞Paul〞,19, 〞Mary〞,18, 〞Adam〞,16};

(〞%cn〞,class[3].name); (〞%cn〞,class[3].name[1]);

(〞%cn〞,class[2].name[1]); (〞%cn〞,class[2].name[0];

7. 下列程序的执行结果为( )。

#include

struct s1

{

char *s;

int i;

struct s1 *sip;

}

main()

{

static struct s1 a[]={{"abcd",1,a+1},{"efgh",2,a+2},{"ijkl",3,a}};

struct s1 *p=a;

int i=0;

printf("%s%s%s",a[0].s,p->s,a[2].sip->s);

printf("%d%d",i+2,--a[i].i);

printf("%cn",++a[i].s[3]); //VC下运行,出现错误

}

abcd abcd 2 0 e efgh ijkl 2 0 e

abcd ijkl 2 0 e abcd abcd 2 1 e

8. 下面程序的输出结果为( )。

#include

struct st

{

int x;

int *y;

} *p;

int dt[4]={10,20,30,40};

struct st aa[4]={50,&dt[0],60,&dt[1],70,&dt[2],80,&dt[3]};

main()

{

p=aa;

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

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

printf("%dn",++(*p->y));

}

A.10 B.50 C. 51 D.60

20 60 60 70

20 21 21 31

9. 有以下程序

#include

main()

{

struct STU

{

char name[9];

char sex;

double score[2];

};

struct STU a={“Zhao”,’m’,85.0,90.0},b={“Qian”,’f’,95.0,92.0};

b=a;

printf(“%s,%c,%2.0f,%2.0fn”,,,[0],[1]);

}

程序的运行结果是:( )。

A. Qian, f, 95, 92 B. Qian, m, 85, 90 C. Zhao, f, 95, 92 D. Zhao, m, 85, 90

10. 下面结构体的定义语句中,错误的是( )。

A. struct ord B. struct ord

{ {

int x; int x ;

int y; int y ;

int z; int z ;

}; }

struct ord a; struct ord a;

C. struct ord D. struct

{ {

int x; int x ;

int y; int y ;

int z; int z ;

} a; }a;

11. 有以下程序

#include

#include

struct A

{

int a;

char b[10];

double c;

};

struct A f(struct A t);

main()

{

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

a=f(a);

printf("%d,%s,%6.1fn",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. 1001,ZhangDa,1098.0 B.1002,ZhangDa,1202.0

C. 1001,ChangRong,1098.0 D.1002,ChangRong,1202.0

12.下面程序的运行结果是( )。

#include

struct STU

{

char name[10];

int num;

};

void f(char *name, int num)

{

struct STU s[2]={{"Sun",2044},{"Li",2045}};

num=s[0].num;

strcpy(name, s[0].name);

}

main()

{

struct STU s[2]={{"Yang",2041},{"Guo",2042}},*p;

p=&s[1];

f(p->name, p->num);

printf("%s %dn", p->name, p->num);

}

A. Sun 2042 B. Sun 2044 C. Guo 2042 D. Yang 2041

13. 下面程序的运行结果是()。

#include

#include

struct STU

{

int num;

float score;

};

void f(struct STU p)

{

struct STU s[2]={{2044,550},{2045,537}};

= s[1].num;

= s[1].score;

}

main()

{

struct STU s[2]={{2041,703},{2042,580}};

f(s[0]);

printf("%d %3.0fn", s[0].num, s[0].score);

}

A. 2045 537 B. 2044 550 C. 2042 580 D. 2041 703

14. 有以下程序:

#include

struct st

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

main()

{

struct st *p=data;

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

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

}

其运行结果是()。

A.10,1 B. 20,1 C. 10,2 D. 20,2

15. 有以程序

#include

#include

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

=;

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

}

main()

{

STU c={“Qian”,’f’,95.0,92.0};

f(c);

printf(“%s,%c,%2.0f,%2.0fn”,,,[0],[1]);

}

程序的运行结果是()。

A. Qian,f,95,92 B. Qian,m,85,90

C. Zhao,f,95,92 D. Zhao,m,85,90

16. 下面程序的运行结果是()。

#include

struct ord

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

main()

{

struct ord *p=dt;

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

printf("%dn", ++p->y);

}

A. 1,2 B. 2,3 C. 3,4 D.4,1

以下结构体类型说明和变量定义中正确的是

A)typedef struct B)struct REC;

{int n; char c;}REC; {int n; char c;};

REC t1,t2; REC t1,t2;

C)typedef struct REC ; D)struct

{int n=0; char c=’A’;}t1,t2; {int n;char c;}REC t1,t2;

填空题

1. 结构体是不同数据类型的数据集合,作为数据类型,必须先说明结构体【 1 】,再说明结构体变量。

2. 有以下说明定义语句,可用引用结构体成员day,请写出引用结构体成员

的其它两种形式【 1 】 、【 2 】。

struct d

{

int day;

char mouth;

int year;

} a,*b;

b=&a;

6.

若已有类型定义:

struct date

{

int year;

int month;

int day;

};

写出下面程序的运行结果【 1 】 。

void change(struct date d)

{

=2008;

==8;

}

main()

{

struct date date1={0,0,0};

change(date1);

printf("%d,%d,%dn",,,);

}

7.

若已有类型定义:

struct date

{

int year;

int month;

int day;

};

写出下面程序的运行结果【 1 】 。

void change(struct date *p)

{

(*p).year=2008;

(*p).month=(*p).day=8;

}

main()

{


本文标签: 结果 程序 结构 定义 运行