2013年12月c语言选择题答案,2013年计算机二级C语言课后模拟题十及答案

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

一 单项选择题

1.以下程序的输出结果是( D )。

struct student

{char name[20];

char sex;

int age;

}stu[3]={“Li Lin”, ‘M’, 18, “Zhang Fun”, ‘M’, 19, “Wang Min”, ‘F’, 20};

main()

{struct student *p;

p=stu;

printf(“%s, %c, %d\n”, p->name, p->sex, p->age);

}

A) Wang Min,F,20

B) Zhang Fun,M,19

C) Li Lin,F,19

D) Li Lin,M,18

2.设有以下语句:

struct st{int n; struct st *next;};

static struct st a[3]={5, &a[1], 7, &a[2], 9, ‘\0’},*p;

p=&a[0];

则表达式( D )的值是6。

A) p++ ->n

B) p->n++

C) (*p).n++

D) ++p->n

3.以下四个程序中,( C )不能对两个整型变量的值进行交换。

A) #include

main()

{int a=10,b=20;

swap(&a,&b);

printf(“%d %d\n”,a,b);

}

swap(int *p,int *q)

{int *t;

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

*t=*p; *p=*q; *q=*t;

}

B) main()

{int a=10,b=20;

swap(&a,&b);

printf(“%d %d\n”,a,b);

}

swap(int *p,int *q)

{int t;

t=*p; *p=*q; *q=t;

}

C) main()

{int *a,*b;

*a=10; *b=20;

swap(a,b);

printf(“%d %d\n”,*a,*b);

}

swap(int *p,int *q)

{int t;

t=*p; *p=*q; *q=t;

}

D) main()

{int a=10,b=20;

int *x=&a,*y=&b;

swap(x,y);

printf(“%d %d\n”,a,b);

}

swap(int *p,int *q)

{int t;

t=*p; *p=*q; *q=t;

}

4.下面程序的输出结果是( C )。

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(“%d ”, ++p->x);

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

printf(“%d\n”, ++(*p->y));

}

A) 10 20 20

B) 50 60 21

C) 51 60 21

D) 60 70 31

5.若要用下面的程序片段使指针变量p指向一个存储整型数据的动态存储单元,则应填入( C )。

int *p;

p= malloc(sizeof(int));

A) int

B) int *

C) (* int)

D) (int *)

6.若已建立下面的链表结构,指针p、s分别指向图中所示的结点,则不能将s所指的结点插入到链表末尾的语句组是(C )。

7545394065a5946703acd63f614bdde2.gif

A) s->next=NULL; p=p->next; p->next=s;

B) p=p->next; s->next=p->next; p->next=s;

C) p=p->next; s->next=p; p->next=s;

D) p=(*p).next; (*s).next=(*p).next; (*p).next=s;

7.以下程序的输出结果是( D )。

#include

void fun(float *p1,float *p2, float *s)

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

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

}

main()

{float a[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

8.字符‘0’的ASCII码的十进制数为48,且数组的第0个元素在低位,则以下程序的输出结果是( B )。

#include

main()

{union

{int i[2];

long k;

char c[4];

}r, *s=&r;

s->i[0]=0x39;

s->i[1]=0x38;

printf(“%c\n”, s->c[0]);

}

A) 39

B) 9

C) 38

D) 8

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

9.若有说明:long *p, a; 则不能通过scanf语句正确给输入项读入数据的程序段是( A )。

A) *p=&a; scanf(“%ld”,p);

B) p=(long *)malloc(8); scanf(“%ld”,p);

C) scanf(“%ld”,p=&a);

D) scanf(“%ld”,&a);

10.以下选项中,能定义s为合法的结构体变量的是( B )。

A) typedef struct abc

B) struct

{double a; {double a;

char b[10]; char b[10];

}s; }s;

C) struct ABC

D) typedef ABC

{double a; { double a;

char b[10]; char b[10];

} }

ABC s; ABC s;

11.设有以下定义和语句,则输出结果是(指针变量占2个字节)( D )。

struct date

{long *cat;(2字节)

struct date *next;(2字节)

double dog;(8字节)

}too;

printf(“%d”, sizeof(too));

A) 20

B) 16

C) 14

D) 12

12.以下程序的输出结果是(D )。

#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];}

A) 1

B) 4

C) 7

D) 5

13.设有如下定义:

struct sk

{int a; float b;} data, *p;

若有p=&data,则对data中的成员a的正确引用是( B )。

A) (*p).data.a

B) (*p).a

C) p->data.a

D) p.data.a

14.以下程序的输出结果是( B )。

#include

struct stu

{int num;

char name[10];

int age;

};

void fun(struct stu *p)

{printf(“%s\n”, (*p).name);}

main()

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

fun (students+2);

}

A) Zhang

B) Zhao

C) Wang

D) 18

15.以下程序运行后,输出结果是( C )。

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

}

A) 1

B) 7

C) 9

D) 11

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

16.下列程序的输出结果是( B )。

struct abc

{ int a, b, c; };

main()

{ struct abc s[2]={{1,2,3},{4,5,6}}; int t;

t=s[0].a + s[1].b;

printf("%d \n", t);

}

A) 5

B) 6

C) 7

D) 8

6afa4f2fc898ab6da84fb9a6482548fc.gif

17.有以下结构体说明和变量的定义,且如下图所示指针p指向变量a,指针q指向变量b。则不能把结点b连接到结点a之后的语句是( B )。

struct node

{char data;

struct node *next;

} a, b, *p=&a,*q=&b;

A) a.next=q;

B) p.next=&b;

C) p->next=&b;

D) (*p).next=q;

18.变量a所占内存字节数是( C )。

union U

{char st[4];

int i;

long l;

};

struct A

{int c;

union U u;

}a;

A) 4

B) 5

C) 6

D) 8

19.有如下定义:

struct person{char name[9]; int age;};

struct person class[10]={“Johu”, 17, “Paul”, 19 , “Mary”, 18, “Adam”, 16};

根据上述定义,能输出字母M的语句是( D )。

A) printf(“%c\n”, class[3].name);

B) printf(“%c\n”, class[3].name[1]);

C) printf(“%c\n”, class[2].name[1]);

D) printf(“%c\n”, class[2].name[0]);

20.以下对结构体类型变量的定义中,不正确的是( C )。

A) typedef struct aa

B) #define AA struct aa

{int n; AA{int n;

float m; float m;

}AA; }td1;

AA td1;

C) struct

D) struct

{ int n; { int n;

float m; float m;

}aa; }td1;

struct aa td1;

21.设有以下说明语句:

struct ex

{int x; float y; char z;} example;

则下面的叙述中不正确的是( B )。

A) struct是结构体类型的关键字

B) example是结构体类型名

C) x, y, z都是结构体成员名

D) struct ex是结构体类型名

22.以下程序的输出结果是(D )。

union myun

{ struct

{ int x, y, z; } u;

int k;

} a;

main()

{a.u.x=4; a.u.y=5; a.u.z=6;

a.k=0;

printf(%d\n", a.u.x);

}

A) 4

B) 5

C) 6

D) 0

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

二 填空题

1.设有以下结构体类型说明和变量定义,则变量a在内存中所占的字节数是 22 ,变量p在内存中所占的字节数是 2 。

struct stud

{char num[6];

int s[4];

double ave;

}a, *p;

2.若有如下结构体说明:

struct STRU

{int a, b ; char c; double d:

struct STRU p1, p2;

};

请填空,以完成对t数组的定义,t数组的每个元素为该结构体类型: struct STRU t[20];

3.以下程序段用于构成一个简单的单向链表,请填空。

struct STRU

{int x, y ;

float rate;

struct STRU * p;

} a, b;

a.x=0; a.y=0; a.rate=0; a.p=&b;

b.x=0; b.y=0; b.rate=0; b.p=NULL;

4.建立并输出100个同学的通讯录,每个通讯录包括同学的姓名、地址、邮政编码。

#include

#define N 100

struct communication

{char name[20];

char address[80];

long int post_code;

}commun[N];

main()

{int i;

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

{set_record(commun+i);

print_record(commun+i);

}

}

set_record(struct communication *p)

{printf(“Set a communication record\n”);

scanf(“%s %s %ld”, p->name , p->address, p->post-code );

}

print_record ( strut communication * p)

{printf(“Print a communication record\n”);

printf(“Name: %s\n”, p->name);

printf(“Address: %s\n”, p->address);

printf(“Post_code: %ld\n”, p->post-code );

}

5.以下函数creatlist用来建立一个带头节点的单链表,新的结点总是插入在链表的末尾。链表的头指针作为函数值返回,链表最后一个节点的next成员中放入NULL,作为链表结束标志。读入时字符以#表示输入结束(#不存入链表)。请填空。

struct node

{char data;

struct node * next;

};

struct node * creatlist( )

{struct node * h,* s,* r;char ch;

h=(struct node *)malloc(sizeof(struct node));

r=h;

ch=getchar( );

while(ch!= ‘#’)

{s=(struct node *)malloc(sizeof(struct node));

s->data= ch ;

r->next=s; r=s;

ch=getchar( );}

r->next= NULL ;

return h;

}

6.有以下定义和语句,则sizeof(a)的值是 10 ,而sizeof(a.share)的值是 4 。

struct date

{int day;

int month;

int year;

union

{int share1;

float share2;

}share;

}a;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值