struct w
{ char low;
char high;
};
union u
{ struct w byte;
short word;
}uw;
main( )
{ int result;
uw.word=0x1234;
printf(“word value:%04x\n”,uw.word);
printf(“high byte:%02x\n”,uw.byte.high);
printf(“low byte:%02x\n”,uw.byte.low);
uw.byte.low=0x74;
printf(“word value:%04x\n”,uw.word);
result=uw.word+0x2a34;
printf(“the result:%04x\n”,result);
}
第1题:
若有下面说明和定义:struct test{ int m1;char m2;float m3;union uu(char u1[5];int u2[2];)ua;}myaa; 则sizeof(struct test)的值是( )。A)20 B)16C)14 D)9
第2题:
● 给定 C 语言的数据结构
struct T {
int w;
union T { char c; int i; double d; } U;
};
假设 char 类型变量的存储区大小是 1 字节,int 类型变量的存储区大小是 4 字节,double类型变量的存储区大小是 8 字节,则在不考虑字对齐方式的情况下,为存储一个 struct T类型变量所需要的存储区域至少应为 (15) 字节。
(15)
A. 4
B. 8
C. 12
D. 17
第3题:
( 38 )有以下定义和语句
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 ) *pw.year = 198O;
B ) w.year=1980;
C ) pw->year=1980;
D ) w.s.year=1980;
第4题:
下列对结构及其变量定义错误的是( )。
A.struct My Struct
B.struct MyStruct{ {int num; int num;char ch; char ch;} }My;
C.strut
D.struct{ {int num; int num;char ch; char ch;}My; };
第5题:
若有下面的说明和定义
struct test
{ int ml; char m2; float m3;
union uu {char ul[5]; int u2[2];} ua;
} myaa;
则sizeof(struct test )的值是
A.12
B.16
C.14
D.9
第6题:
下列程序的输出结果是( )。 #include "stdio.h" main() { struct st { int y,x,z;}; union {long i;int j; char k;} un; printf("%d,%d\n",sizeo(struct st),sizeof(un)); }
A.6,2
B.6,4
C.8,4
D.8,6
第7题:
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char*filename,char*word)是从指定的文件中得到单词。char*strdup(char*S)是复制S所指向的字符串,并返回复制字符串的地址。
[C程序]
include <stdio.h>
include <ctype.h>
include <string.h>
define MAXWORD 100
struct node {
char*word;
int count;
struct node*left;
struct node*right;
}
struct node*addtree(struct node*P,char*w)
{ int cond;
if(p==NULL){ /*向树中插入结点*/
P=(struct node*)malloc(sizeof(struct node));
P->word=strdup(w);
P->count=1;
(1) ;
}
elseif((oond=strcmp(w,p->word))==0) (2) ;
else if(cond<0)p->left=(3);
else p->right=(4);
return p;
}
main()
{ Struct node*root;
char word[MAXWORD];
root=NULL;
filename="example.dat";
while(getword(filename,word)!=EOF))
root=(5);
}
第8题:
若有以下说明和定义语句,则变量w在内存中所占的字节数是 【19】 。
union aa {float x; float y; char c[6]; };
struct st{ union aa v; float w[5]; double ave; } w;
第9题:
看这段程序,可是执行。#include <stdio.h>int main(int argc, char *argv[]){ struct info { char name[33]; int age; }; struct info aa[3]={"meng",20,"juan",29,"an",59}; struct info *p=aa; for(int i=0;i<3;i++,p++) printf("%-6s %d\n",p->name,p->age);}将其改成这样:#include <stdio.h>int main(int argc, char *argv[]){ struct info { char name[33]; int age; }; struct info aa[3]={"meng",20,"juan",29,"an",59}; //struct info *p=aa; for(int i=0;i<3;i++,aa++) printf("%-6s %d\n",aa->name,aa->age);}为什么就执行不了呢
第10题:
变量a所占内存字节数是______。 union U { char st[4]; int i; long 1; }; struct A { int c; union U u; }a;
A.4
B.5
C.6
D.8