以下程序的运行结果是( ) #include struct s { int num; char name[20]; int age; }; fun(struct s *p) { printf("%s ",(*p).name); } void main( ) { struct s stud[3]={{101,"Li",18},{102,"Wang",19},{103,"Zhang",21}}; fun(stud+2); }
A: Li
B: Wang
C: Zhang
D: 不确定的值
A: Li
B: Wang
C: Zhang
D: 不确定的值
举一反三
- 根据程序,请判断输出结果:#include<stdio.h>struct stu{int num;char name[5];int age;char sex;};void fun(struct stu *p){printf("%s\n",(*p).name);}main(){struct stu stud[3]={{0001,"zhang",20,'f'},{0002,"li",18,'m'},{0003,"chen",19,'f'}};fun(stud+2);}
- 以下程序有三处语法错误,请指出#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;}
- 有以下程序段,输出结果为()。 #include<stdio.h> struct person {char name[20]; int count; }leader[3]={"Li",0,"Zhang",0,"Sun",0}; main() {printf("%s",leader[1].name); }
- 以下变量定义,错误的是: A: struct student{int num, char name[20];} s; B: struct {int num, char name[20];} s; C: struct student{int num, char name[20];}; struct student s; D: struct student{int num, char name[20];} ; student s
- 下列程序的输出结果第一行是_____,第二行是_______。 #include [iostream] #include [cstring] #include [iomanip] using namespace std; struct student { int num; char name[20]; double score; }; void fun(struct student *s); int main() { struct student stu={12345, "Zhangwei", 98.0}; cout[<stu.num<<","<<stu.name<<","<<stu.score<<endl; fun(&stu); cout<<stu.num<<","<<stu.name<<","<<stu.score<<endl; return 0; } void fun(struct student *s) { s-]num=23456; strcpy(s->name, "Liming"); s->score=88; }