假设以下代码运行环境为32位系统,其中,__attribute__((packed))的作用是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐。代码段1:struct student1{char name[10];long sno;char sex;float score[4];}__attribute__((packed))*p1,a1,b1;代码段2:union student2{char name[10];long sno;char sex;float score[4];}*p2,a2,b2;sizeof(struct student1)、sizeof(union student2)的结果分别是______。A.248和128B.31和31C.31和16D.16和16

假设以下代码运行环境为32位系统,其中,__attribute__((packed))的作用是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐。代码段1:struct student1{char name[10];long sno;char sex;float score[4];}__attribute__((packed))*p1,a1,b1;代码段2:union student2{char name[10];long sno;char sex;float score[4];}*p2,a2,b2;sizeof(struct student1)、sizeof(union student2)的结果分别是______。

A.248和128
B.31和31
C.31和16
D.16和16

参考解析

解析:本题考查程序开发的基础知识。题目中student1是一个结构体,sizeof(struct student1)结果为结构体student1所有元素字节数之和,因此sizeof(struct student1)结果为:10+4+1+16=31字节。题目中student2是个联合,sizeof(union student2)结果是联合student2中最长一个元素的字节数。因此sizeof(union student2)结果为:16字节。

相关考题:

有以下程序#include stdio.h#include string.htypedef struct{ char name[9];char sex; float score[2]; } STU;STU 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];return a;}main(){ STU c={"Qian",'f',95.0,92.0},d;d=f(c); printf("%s,%c,%2.0f,%2.0f\n",d.name,d.sex,d.score[0],d.score[1]);}程序的运行结果是A)Qian,f,95,92B)Qian,m,85,90C)Zhao,m,85,90D)Zhao,f,95,92

有以下程序#include stdio.hmain(){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]);}程序的运行结果是A)Qian,f,95,92B)Qian,m,85,90C) Zhao,f,95,92D)Zhao,m,85,90

若有以下说明和定义语句,则变量w在内存中所占的字节数是 【19】 。union aa {float x; float y; char c[6]; };struct st{ union aa v; float w[5]; double ave; } w;

下列语句段中,正确的是( )。A.struct{int x;float y;int a[2];unsigned b[3];char name[10];};B.struct stu{unsigned a[3];unsigned b[4];}x;int*p=x.a;C.struct stu{int a;float x[4];}y={1,1.0};float data=y.x;D.struct nd{int a,b;unsigned c[2]=5;};

有下列程序:includeinclude "string.h"typedef struct{char name[9]; char sex;float 有下列程序: #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]; } 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.Qian,f,95,92B.Qian,m,85,90C.Zhao,f,95,92D.Zhao,m, 85,90

阅读以下说明和C语言代码,回答问题1至问题5,将解答填入答题纸的对应栏内。[说明]在实模式存储管理方案下,嵌入式系统的内存地址空间的布局一般可以分为五个段:代码段(text)、数据段(data)、bss段(bss)、堆(heap)和栈(stack)。图16-4为一段例程。1: include2: unsigned char gvCh;3: unsigned short gvShort;4: unsigned int gvInt = 0x12345678;5: unsigned long gvLong = 0x87654321;6: void main(void)7: {8: unsigned char array[lO],*p;9: p = malloc(lO*sizeof(char));10: while (1);代码段、数据段和bss段的大小是在什么时候确定的?

下面程序和运行运行结果是【 】。typedef union student{ char name [10];long sno;char sex;float score [4];} STU;main ( ){ STU a[5];prinff( "% d\n", sizeof(a) );}

变量a所占内存字节数是______。 union U { char st[4]; int i; long 1; }; struct A { int c; union U u; }a;A.4B.5C.6D.8

有以下程序 include include typedef struct { cha 有以下程序 #include <stdio.h> #include <string.h> typedef struct { char name[9]; char sex; float score[2]; } STU; STU 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]; return a; } main() { STU c={"Qian", T, 95.0, 92.0}, d; d=f(c); printf("%s,%c,%2.0f,%2.0f\n", d.name, sex, score[O], d.score[1]); } 程序的运行结果是A.Qian, f,95,92B.Qian,m,85,90C.Zhao,m,85,90D.Zhao,f,95,92

有以下程序 include main() { struct STU{char name[9];char sex;double 有以下程序 #include <stdio.h> main() { struct STU{char name[9];char sex;double score[2];}; sturt 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]); } 程序的运行结果是______。A.Qian,f,95,92B.Qian,85,90C.Zhao,f,95,92D.Zhao,m,85,90

变量a所占的内存字节数是 ______。A.4B.5C.6D.8 union U { char st[4]; int i; long l; }; Struct A{ int c; union U u; }a;

阅读以下程序段,在实模式存储管理方案中,gvCh存放在(36)中;main函数编译后的代码存入在(37)中;指针p存放在(38)中。#include<malloc. h>unsigned char gvCh;unsigned short gvShortunsigned int gvInt=0x12345678unsigned long gvLong=0x23456789;ovid main(void){ unsigned char array[10], *p;p=malloc(10 * sizeof(char))while(1)}A..text段B..data段C..bss段D.堆空间

有如下程序段#include "stdio.h"typedef union{ long x[2]; int y[4]; char z[8];}atx;typedef struct aa { long x[2]; int y[4]; char z[8];} stx;main(){ printf("union=%d,struct aa=%d\n",sizeof(atx),sizeof(stx));}则程序执行后输出的结果是A.union=8,struct aa=8 B.union=8,struct aa=24C.union=24,struct aa=8 D.union=24,struct aa=24

下面程序的运行结果是typedef union student{ char name[10]; long sno; char sex; float score[4];}STU;main(){ STU a[5]; printf("%d\n",sizeof(a));}

有以下程序: #includestdio.h struct STU{char name[9];char sex;int score[2];}; void f(struct STU a[]) { struct STU b={"Zhao",m,85,90); a[1]=b; } main( ) { struct STU c[2]={{"Qian",f,95,92},{"Sun",m 98,99}}; f(c); printf(”%s,%c,%d,%d,¨,c[o].name,c[o].sex,c[o].score[o],c[o].score[1]); printf("%s,%c,%d,%d\n",c[1].name,c[1].sex,c[1].score[o],c[1].score [1]); } 程序运行后的输出结果是( )。A.Zhao,m,85,90,Sun,m,98,99B.Zhao,m,85,90,Qian,f,95,92C.Qian,f,95,92,Sun,m,98,99D.Qian,f,95,92,Zhao,m,85,90

变量a所占的内存字节数是______。 union U { char st[4]; int i; long 1; }; struct A { int c; union U u; }a;A.4B.5C.6D.8

有以下程序 include include typedef stmct{ char name[9];char sex;flo 有以下程序#include <stdio.h>#include <string.h>typedef stmct{ 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];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.Qian,f,95,92B.Qian,m,85,90C.Zhao,f,95,92D.Zhao,m,85,90

下列语句段中,正确的是( )。A.struct { int x; float y; int a[2]; unsigned b[3]; char name[ 10]; };B.struct stu { unsigned a[3]; unsigned b[4]; }x; int *p= x.a;C.street stu { int a; float x[4]; }y={1,1.0}; float data=y.x;D.struct nd {int a,b; unsigned c[2]=5; };

阅读以下说明,回答问题1至问题3,将答案填入答题纸对应栏内。【说明】在某嵌入式处理器上,编写以下两段秸序(编译选项中,存储采用4字节对齐方式)。程序段1:struct studentl {char name [10] ;long sno;char sex;float score [4] ;*pl, al, bl;程序段2:union student2 {char name [10] ;long sno;char sex,float score [4] ;*p2, a2, b2;汉诺塔问题说明:有n个盘子在A处,盘子从小到大,最上面的盘予最小,程序要把这n个盘子从A处搬到C处,可以在E处暂存,但任何时候都不能出现大的盘子压在小的盘子上面的情况。下列是一段求解汉诺塔问题的C语言程序。include stdio . hvoid move (int n, char a, char c){static int Step=l;printf (Step %2d: Disk %d %c..-- %c\n, Step, n, a, c) ;Step++;}void Hanoi (int n, char a, char b, cnar c){if (nl){Hanoi (n-l, a, c, b) ;move (n, a. c) ;Hanoi (n-l, b, a, c) ;}else move (n,a,c);}void main(){Hanoi(3, ’A’, 、B’, 、C ’);}【问题1】(3分)C语言函数的一般格式为:函数类型 函数名 (参数列表){函数体;}简答下述问题,将答案填写在答题纸中对应栏目。(l)函数类型的含义是什么?(2)参数列表的含义是什么?(3)C语言函数之间的参数如何传递?【问题2] (6分)回答问题,将答案填写在答题纸中对应栏目。(1)sizeof(struct studentl)结果是多少(2) sizeof(union student2)结果是多少(3)变量a2在程序段2中定义,写出执亍以下语句后的输出结果。strcpy (a2. name,¨zhangwei¨);a2.sex=’f’;printf (%s¨, a2 .name);【问题3](6分)仔细阅读求解汉诺塔问题的C语言程序,完成其中(1)~(4)空白填空,将答案填入答题纸的对应栏内。运行结果为:Step1:Disk l A----CStep 2: (l)Step 3: Disk I C----BStep4: (2)Step 5: (3)Step 6: Disk 2 B----CStep 7: (4)

有以下程序:includeincludetypedef struct{char name[9];char sex;float s 有以下程序: #include <stdio.h> #include <string.h> typedef struct{char name[9];char sex;float score[2]}STU; STU f(STU A) {STU b={"Zhao",'m',85.0,90.0}; int i; strcpy(a.name,b.namC) ; a.sex=b.sex; for(i=0;i<2;i++) a.score[i]=b.score[i]; return a; } main() {STU c={"Qian",'f',95.0,92.0},d; d=f(C) ; pintf("%s,%c,%2.of.%2.of\n",d.name,d.sex,d.score[0],score[1]); } 程序的运行结果是( )。A.Qian,f,95,92B.Qian,m,85,90C.Zhao,m,85,90D.Zhao,C95,92

以下代码中变量result的可能类型有哪些?byte b = 11;short s = 13;result = b * ++s; A.byte, short, int, long, float, doubleB.boolean, byte, short, char, int, long, float, doubleC.byte, short, char, int, long, float, doubleD.byte, short, charE.int, long, float, double

编译器和解释器是两种基本的高级语言处理程序。编译器对高级语言源程序的处理过程可以划分为词法分析、语法分析、语义分析、中间代码生成、代码优化、目标代码生成等阶段,其中,( )并不是每个编译器都必需的,与编译器相比,解释器( )。A.词法分析和语法分析B.语义分析和中间代码生成C.中间代码生成和代码优化D.代码优化和目标代码生成

以下程序段的输出结果是()。      union node      {int a;      float b;      Char C[10];};    printf(”%d”,sizeof(union node));

单选题有以下程序#include #include typedef struct{ char name[9]; char sex; float score[2];} STU;STU 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]; return a;}main(){ STU c={Qian,'f',95.0,92.0},d; d=f(c); printf(%s,%c,%2.0f,%2.0f, d.name, d.sex, d.score[0], d.score[1]);}程序的运行结果是(  )。AQian,m,85,90BZhao,m,85,90CQian,f,95,92DZhao,f,95,92

单选题有以下程序:#include struct STU{ char name[9]; char sex; int score[2];};void f(struct STU a[]){ struct STU b={zhao,'m',85,90}; a[1]=b;}main(){ struct STU c[2] = {{Qian,'f',95,92}, {Qian,'f',95,92}}; f(c); printf(%s,%c,%d,%d,, c[0].name, c[0].sex, c[0].score[0], c[0].score[1]); printf(%s,%c,%d,%d, c[1].name, c[1].sex, c[1].score[0], c[1].score[1]);}程序运行后的结果是(  )。AZhao,m,85,90,Sun,m,98,99BZhao,m,85,90,Qian,f,95,92CQian,f,95,92,Sun,m,98,99DQian,f,95,92,Zhao,m,85,90

单选题有以下程序:#include #include typedef struct{ char name[9]; char sex; float score[2];} STU;void f(STU *A){ strcpy(a-name,Zhao); a-sex='m'; a-score[1]=90.0;}main(){ STU c = {Qian,'f',95.0,92.0},*d=c; f(d); printf(%s,%c,%2.0f,%2.0f, d-name, c.sex, c.score[0], c.score[1]);}程序的运行结果是(  )。AQian,f,95,92BZhao,f,95,90CZhao,m,95,90DZhao,f,95,92

单选题有以下程序:#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.0f, b.name, b.sex, b.score[0], b.score[1]);}程序运行的结果是(  )。AQian,f,95,92BQian,f,85,90CZhao,f,95,92DZhao,m,85,90