第五章
下面结构体的定义语句中错误的是( ).
struct {int num,char name[20];} a;
struct st{int num,char name[20];} a;
struct st{int num,char name[20];} ;st a;
答案:struct st{int num,char name[20];} st a;
struct abc{int x;int y;} data1=(2,3),data2;则以下赋值语句中错误的是( )。
data2.x=data1.x;
data2=data1;
data2(9,10);
答案:data2(9,10);
struct abc{int x;char y[20];double z;} data;则以下给结构体变量成员x赋值语句中正确的是( )。
data.x=100;
data->x=100;
*data.x=100;
答案:data.x=100;
struct s {int a,b;} data[2]={10,100,20,200};int main(){s p=data[1];cout<<p.a<<endl;return 0;}程序运行后的输出结果是( )。
10
11
20
答案:20
运行程序,程序输出结果是( )。#include <iostream>using namespace std;int main(){ struct stud{ char num [5]; int s[4]; double ave; } a; cout<<sizeof(stud)<<endl; return 0;}
29
答案:32
有下列结构体声明语句struct student{int num; char name[20]; float score[3]; };student s[3]={123,"Li Fang",67,89,90};要对第1个学生的成绩输出总分,下列表达式正确的是( ).
cout<<s[0].score[0]+s[0].score[1]+s[0].score[2];
cout<<score[0].s[1]+ score[1].s[1]+score[2].s[1];
cout<<s.score[0]+s.score[1]+s.score[2];
答案:cout<<s[0].score[0]+s[0].score[1]+s[0].score[2];
定义以下结构体类型,运行程序的输出结果是( )。#include <iostream>using namespace std;int main(){struct s{int a;double b;};cout<<sizeof(s)<<endl;return 0;}
答案:16
当定义一个结构体变量时,系统为它分配的内存空间是( ).
结构中一个成员所需的内存容量
结构体中占内存容量最大者所需的容量
结构中各成员所需内存容量之和
答案:结构中各成员所需内存容量之和
运行程序,程序输出结果为( )#include <iostream>using namespace std;int main(){ struct s { int x; } a[3]; cout<<sizeof(a); return 0;}
答案:12
定义以下结构体数组,运行程序,程序输出结果是( )。 #include <iostream>using namespace std;int main(){ struct c { int x; int y; } s[2]={1,3,2,7}; cout<<s[0].x*s[1].x<<endl;return 0;}
答案:2
运行程序,程序运行结果是( ) #include <iostream>using namespace std;struct KeyWord{ char Key[20]; int ID; } kw[]={"void",1,"char",2,"int",3,"float",4,"double",5};int main(){ cout<<kw[3].Key[0]<< ","<< kw[3].ID ; return 0; }
n,3
i,3
l,4
答案:f,4
#include <iostream>using namespace std;struct student { char name[10]; int score[50]; float average; } stud1; int main(){ cout<<sizeof(student);return 0;}
答案:216
运行程序,程序运行结果是( )。 #include <iostream>using namespace std;int main(){struct person{ char name[9]; int age;};person a[5]={"John",17,"Paul",19,"Mary",18,"Adam",16};cout<<a[2].name;return 0;}
Adam
Mary
John
答案:Mary
运行程序,程序运行结果是( ) #include <iostream>using namespace std;int main(){ struct date{ int year; int month; int day;};struct s{ date birthday; char name[20]; } x[4]={{2008,10,1, "guangzhou"},{2009,12,25,"Tianjin"}};cout<< x[0].name<<","<<x[1].birthday.year<<endl;return 0;}
Tianjin,2009
guangzhou,2009
guangzhou,2008
答案:guangzhou,2009
运行程序,程序输出结果是( )。#include <iostream>using namespace std;struct contry{int num;char name[20]; } x[5]={1,"China",2,"USA",3,"France",4,"Englan",5,"Spanish"};int main(){ int i; for (i=3;i<5;i++) cout<<x[i].num<<","<<x[i].name[0]<<endl;return 0;}
4E5S
3F4E5S
F4E
答案:4E5S

点赞(0) dxwkbang
返回
顶部