以下程序有三处语法错误,请指出#include<;stdio.h>;struct student{short num;char name[20];char sex;short age;}int main(){struct student stu[4] = {{112,"Wang Lin",'M',15},{113,"Li",'W',20}};struct student *p;stu[2].num = stu[1].num+1;stu[2].name = stu[1].name;stu[2].sex = 'W';stu[2].age = 23;printf("%s\n",stu[2].name);p = &stu[3];*p = stu[0];printf("%s",p.name);return 0;}
举一反三
- 编写input()函数输入5个学生的数据记录。(用结构体设计,学生记录中包括学号、姓名、四门课程成绩).【1】、【2】分别填写的是( )。 #include#define N 5 struct student { char num[6]; char name[8]; int score[4]; } stu[N]; void input(struct student stu[]); void print(struct student stu[]); main() { input(stu); } void input(struct student stu[]) { int i,j; for(i=0;i A: stu[i].num B: stu[i+1].num C: stu[i].name D: stu[j].name
- 对以下定义,能输出字符串"Mary"的语句是( )。struct student { char name[20]; int age; }; struct student stu[100]={"John",16,"Paul",17,"Mary",18 }; A: printf("%s",stu[2].name); B: printf("%s",stu[1].name); C: printf("%s",stu[2]); D: printf("%s",stu[1]);
- 设有以下定义struct student{ int age; int num;}stu[5],*p=stu;int i;stu[0].num=10;则以下语句不正确的是 A: i=p->num; B: i=stu[0].num; C: i=(*p).num; D: p=&student.num;
- void sort()//按个人平均成绩高低排序{ int i,j,k,t=0;double temp;char str[10]="";for(i=0;i< ;i++)for(j= ;j<N;j++)if(stu[i].av<stu[j].av){temp=stu[i].av;stu[i].av=stu[j].av;stu[j].av=temp;strcpy(str,stu[i].num);strcpy(stu[i].num,stu[j].num);strcpy(stu[j].num,str);strcpy(str,stu[i].name);strcpy(stu[i].name,stu[j].name);strcpy(stu[j].name,str);for(k=0;k<3;k++){t=stu[i].score[k];stu[i].score[k]=stu[j].score[k];stu[j].score[k]=t;}}[/i][/i][/i][/i][/i][/i][/i][/i][/i]
- struct student{ int age; char num[8];};struct student stu[3]={{20,"200401"},{21,"200402"},{19,"200403"}};struct student *p=stu;以下选项中引用错误的是___ __。 A: (p++)->;num B: p->;num C: (*p).num D: stu[3].age