单选题设有以下程序段:struct MP3{ char name[20]; char color; float price;}std,*ptr;ptr=std;要引用结构体变量std中的color成员,下列写法中错误的是( )。Astd.colorBptr-colorCstd-colorD(*ptr).color
单选题
设有以下程序段:struct MP3{ char name[20]; char color; float price;}std,*ptr;ptr=&std;要引用结构体变量std中的color成员,下列写法中错误的是( )。
A
std.color
B
ptr->color
C
std->color
D
(*ptr).color
参考解析
解析:
结构体变量的引用两种方式:①用箭头操作符:“->”,其中操作数必须是指向结构的指针,右操作数是该结构的成员;②结构体变量名.成员名。C项,“std”是结构体变量名,应该使用“.”操作符来引用结构体成员。答案选择C选项。
结构体变量的引用两种方式:①用箭头操作符:“->”,其中操作数必须是指向结构的指针,右操作数是该结构的成员;②结构体变量名.成员名。C项,“std”是结构体变量名,应该使用“.”操作符来引用结构体成员。答案选择C选项。
相关考题:
有以下程序段int j; float y; char name[50];scanf("%2d%f%s",j,y,name);当执行上述程序段,从键盘上输入 55566 7777abc 后, y 的值为A ) 55566.0B ) 566.0C ) 7777.0D ) 566777.0
设有以下程序段:struct MP3{ char name[20];char color;float price;}std,*ptr;ptr=std:若要引用结构体变量std中的color成员,写法错误的是( )。A.std.colorB.ptr->colorC.std->colorD.(*ptr)color
下列语句段中,正确的是( )。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数组名称是指针变量吗? 看这段程序,可是执行。#include stdio.hint 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;i3;i++,p++) printf("%-6s %d\n",p-name,p-age);}将其改成这样:#include stdio.hint 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;i3;i++,aa++) printf("%-6s %d\n",aa-name,aa-age);}为什么就执行不了呢
有以下程序includestruct STU{char name[10];int num;};void f(char*name, intnum){s 有以下程序 #include <string.h> struct STU { char name[10]; int num; }; void f(char *name, int num) { struct STU s[2]={{"SunDan",20044},{"Penghua",20045}}; num=s[0].num; strcpy(name,s[0].name); } main() { struct STU s[2]={{"YangSan",20041},{"LiSiGuo",20042}},*p; p=s[1]; f(p->name,p->num); printf("%s %d\n",p->name,p->num); } 程序运行后的输出结果是A.SunDan 20042B.SunDan 20044C.LiSiGuo 20042D.YangSan 20041
有以下程序段 int j; float y; char name[50]; scanf("%2d%f%s",j,y,name); 当执行上述程序段,从键盘上输入55566 7777abc后,y的值为A.55566B.566C.7777D.566777
有以下程序: include struct STU (char name[10]; int num; }; 有以下程序: #include <string.h> struct STU (char name[10]; int num; }; void f(char *name, int num) {struct STU s[2]={{"SunDan",20044}.{"Penghua",20045}}; num=s[0].num; strcpy(name,s[0].name); } main() {struct STU s[2]={{"YangSall",20041},{"LiSiGao",20042}},*p;p=s[1]; f(p->name,p->num); printf("%s%d\n",p->name,p->num); } 程序运行后的输出结果是 ______。A.SunDan 20042B.SunDan 20044C.LiSiGuo 20042D.YangSan 20041
有以下程序#include "stdio.h"main(){ struct date { int number; float fenzhi; char name; }stu; printf("%d\n",sizeof(stu));} 程序的运行结果是A.3 B.5C.7 D.8
以下程序的输出结果是【】。 include main() {struct stru {int a; float b; char d[4]; } 以下程序的输出结果是【 】。include<stdio.h>main(){ struct stru{ int a;float b;char d[4];};printf("%d\n",sizeof(struct stru));}
有以下程序 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
下面程序的运行结果是typedef union student{ char name[10]; long sno; char sex; float score[4];}STU;main(){ STU a[5]; printf("%d\n",sizeof(a));}
设有以下程序段: struct MP3 { char name[20]; char color; float price; }std,*ptr; ptr=std: 若要引用结构体变量std中的color成员,写法错误的是( )。A.std.colorB.ptr-colorC.std-colorD.(*ptr)color
以下程序的输出结果是______。includestruct stu{int num; char name[10]; int age;};v 以下程序的输出结果是______。#include<stdio.h>struct stu{ int num; char name[10]; int age;};void fun(struct stu*p){ printf("%s\n",(*p).name);}main(){ struct stu students[3]={ {9801,"Zhang",20}, { 9802,"Wang",19}, { 9803,"Zhao",18} }; fun(students+2);}A.ZhangB.ZhaoC.WangD.18
下列语句段中,正确的是( )。A.street { 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.stmct stu { int a; float x[4]; }y={1,1.0}; float data=y.x;D.struct nd { int a,b; unsigned c[2]=5; };
有以下程序 include struct STU { char num[10]; float score[3];}; void ma 有以下程序 #include<iostream.h> struct STU { char num[10]; float score[3];}; void main( ) { struct STU s[3]={ { "20021",90,95,85 }, {"20022",95,80,75 }, {"20023",100,95,90 } },* p=s; int i; float sum=0; for(i=0;i<A.260B.270C.280D.285
下列关于结构型变量的定义语句中,错误的是( )A.typedef struct CCCB.define GGG struct { char name[20];GGG CCC { char name[20]; int age; int age; }GGG; }; GGG abc ; GGG CCC abc;C.structD.struct { char name[20]; { char name[20]; int age; int age; }ccc; }abc; CCC abc;
有以下程序:includeinclude struct STU {char name[10];int hum;};void f( 有以下程序:#include <stdio.h>#include <strine.h> struct STU { char name[10]; int hum;};void f(char * name,iht num){ struct STU s[2] = {{ "SunDan" ,20044} , {" Penghua" ,20045}}; num= s[0]. nnm; strepy(name,s[0], name);}main( ){ struct STU s[2] = {{"YangSan" ,20041 }, { "LiSiGao" ,20042}}, * P; p = s[1]; f(p->name,p->hum); printf("% s %d \n" ,p-> name,p->num);}程序运行后的输出结果是( )。A.SunDan 20042B.SunDan 20044C.LiSiGuo 20042D.YangSan 20041
下列语句段中,正确的是( )。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; };
有以下程序: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
假设以下代码运行环境为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
假定有“struct BOOK{char title[40]; float price;} book;”,则正确的语句为()。Astruct BOOK x= book;Bstruct BOOK *x=book;Cstruct BOOK x=calloc(BOOK);Dstruct BOOK *x=BOOK;
假定有“struct BOOK{char title[40]; float price;}; struct BOOK book;”,则不正确的语句为()。Astruct BOOK *x=malloc(book);Bstruct BOOK x={"C++ Programming",27.0};Cstruct BOOK *x=malloc(sizeof(struct BOOK));Dstruct BOOK *x=book;
单选题有以下函数:#include struct stu{ int num; char name[10]; int age;};void fun(struct stu *p){ printf(%s, p-name);}main(){ struct stu x[3] = {{01,Zhang,20}, {02,Wang,19}, {03,Zhao,18}}; fun(x+2);}程序运行后的输出结果是( )。AZhangBZhaoCWangD19
单选题假定有“struct BOOK{char title[40]; float price;}; struct BOOK book;”,则不正确的语句为()。Astruct BOOK *x=malloc(book);Bstruct BOOK x={C++ Programming,27.0};Cstruct BOOK *x=malloc(sizeof(struct BOOK));Dstruct BOOK *x=book;
填空题以下程序段的输出结果是()。 struct node {int a; float b; char c[10];} printf(“%d”,sizeof(struet node)) ;