- 求 sizeof(name1)?(晟安信息)
struct name1{
char str;
short x;
int num;
};
答 :8
- (电工时代)
typedef struct _a
{
char c1;
long i;
char c2;
double f;
}a;
typedef struct _b
{
char c1;
char c2;
long i;
double f;
}b;
sizeof(a) = _____32__;
sizeof(b) = _____24__;
- 给了一个结构体,求 sizeof(struct A) = __16______。 (鲁科安全,软通动力)
struct A{
char a;
char b;
char c;
short d;
int e;
short f;
}
- 有一个如下的结构体,请问在64位编译器下用 sizeof(struct A) 计算出的大小是多少?(A ) (鲁科安全)
struct A{
long a1;
short a2;
int a3;
int *a4;
}
A. 24 B. 28 C. 16 D. 18
- 有以下说明语句,则下列错误的引用 是(B )。(山大华天)
struct stu
{
int no;
char name[21];
};
stu w, *p = &w;
A. w.no B*p.no C. p->no D. (*p).no
- 写出下述程序结果: (中维世纪)
typedef struct test
{
char x1;
short x2;
float x3;
char x4;
}TEST_T;
printf("%d", sizeof(TEST_T));
答:12
- 下面的代码输出是什么,为什么?(64位环境) (信雅达)
struct {
char *a1;
long a2;
short a3;
}A;
int main(void)
{
printf("%d", sizeof(A));
}
答:24
- 设有如下结构定义: struct student { int num; char name[20]; char sex; int age; char addr[30];} stud; 若用printf("%s\n", .....)访问该结构中name值的正确方法是 (D ) (杭州快越科技)
A. stud -> name B. &stud.name
C. stud.&name D. stud.name
- struct
{
short a; char b; float c;
}cs;
则sizeof(cs)的值是(D ) (苏州特点电子科技)
A.4 B.5 C.7 D.8
- 如下函数的输出结果是:【 】
struct node
{
char a; short b; char c; int d;
};
struct node s = { 3, 5, 6, 99 };
struct node *pt = &s;
printf("%X\n", *(int*)pt);
答案:0x06000503
- 编程题:定义学生结构体,存储学生的学号、姓名、分数,定义长度为5的结构体数组,实现:
①输入学生信息
②输出学生信息
③计算学生的成绩总分、平均分
④按照学生的分数进行排序
⑤输出排序后的数组
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct{
int id;
char name[20];
float score;
}Student;
int main(int argc, const char *argv[])
{
Student stu[5];
for(int i=0;i<5;i++){
printf("请输入第%d学生学号:",i+1);
scanf(" %d",&stu[i].id);
printf("请输入第%d学生姓名:",i+1);
scanf(" %s",stu[i].name);
printf("请输入第%d学生分数:",i+1);
scanf(" %f",&stu[i].score);
printf("\n");
}
float sum = 0;
for(int i=0;i<5;i++){
printf("学号:%d 姓名:%s 分数:%.2f\n",stu[i].id,stu[i].name,stu[i].score);
sum += stu[i].score;
}
printf("学生总分为:%.2f,\n平均分为:%.2f\n",sum,sum/5);
Student t;
for(int i=1;i<5;i++){
for(int j=0;j<5-i;j++){
if(stu[j].score<stu[j+1].score){
t.id=stu[j].id;strcpy(t.name,stu[j].name);t.score=stu[j].score;
stu[j].id=stu[j+1].id;strcpy(stu[j].name,stu[j+1].name);stu[j].score=stu[j+1].score;
stu[j+1].id=t.id;strcpy(stu[j+1].name,t.name);stu[j+1].score=t.score;
}
}
}
printf("排序后的输出为:\n");
for(int i=0;i<5;i++){
printf("学号:%d 姓名:%s 分数:%.2f\n",stu[i].id,stu[i].name,stu[i].score);
}
return 0;
}