c9-5.c 712 B

1234567891011121314151617181920
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {struct student
  5. {long num;
  6. char name[20];
  7. char sex;
  8. float score;
  9. };
  10. struct student stu_1; // 定义struct student类型的变量stu_1
  11. struct student * p; // 定义指向struct student 类型数据的指针变量p
  12. p=&stu_1; // p指向stu_1
  13. stu_1.num=10101; // 对结构体变量的成员赋值
  14. strcpy(stu_1.name,"Li Lin");
  15. stu_1.sex='M';
  16. stu_1.score=89.5;
  17. printf("No.:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",stu_1.num,stu_1.name,stu_1.sex,stu_1.score); // 输出结果
  18. printf("\nNo.:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",(*p).num,(*p).name,(*p).sex, (*p).score);
  19. return 0;
  20. }