[结构体、共用体和用户定义类型.doc
文本预览下载声明
用typedef说明一种新类型名
选择题
1)设有如下说明:
typedef struct ST
{long a;
int b;
char c[2];
}NEW;
则下列叙述中正确的是———c———
a)以上的说明形式非法 b)ST是一个结构体类型
c)NEW是一个结构体类型 d)NEW是一个结构体变量
2)设有以下语句:
typedef struct s
{
int g;
char h;
}T;
则下面叙述中正确的是———b———
a)可用S定义结构体变量 b)可以用T定义结构体变量
c)S是struct类型的变量 d)T是struct S类型的变量
结构体类型
选择题
1)有以下程序
#include stdio.h
struct st
{int x,y;}data[2]={1,10,2,20};
main()
{
struct st *p=data;
printf(“%d,”,p-y);printf(“%d\n”,(++p)-x);
}
程序运行结果是____c_____
a)10,1 b)20,1 c)10,2 d)20,2
2)有以下程序
#include stdio.h
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.0f\n”,b.name,b.sex,b.score[0],b.score[1]);
}
程序运行的结果是____D_____
a)Qian,f,95,92 b)Qian,m,85,90 c)Zhao,f,95,92 d)Zhao,m,85,90
3) 将定已建立以下链表结构,且指针p和q已指向如图所示的结点:
则以下选项中科将q所指结点从链表中删除并释放该结点的语句是_____d____
a) (*p).next=(*q).next;free(p); b)p=q-next; free(q);
c) p=1; free(q); d) p-next=q-next;free(q);
4)以下结构体类型说明和变量定义中正确的是____a____
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;
REC t1,t2;
5)有以下程序
#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;i2;i++) a.score[i]=b.score[i];
}
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____
a)Qian,f,95,92 b)Qian,m,85,90 c)Zhao,f,95,92 d)Zhao,m,85,90
6)有以下程序
#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};
main()
{int i;
p=a;
for(i=1;i=2;i++) {printf(“%d,”,p-x); p=p-y;}
}
程序的运行结果是____d_____
a) 20,30, b) 30,17 c)15,
显示全部