例11.3.txt

来自「C语言课件,清华大学出版的书的配套的.很好用,尽管下载.」· 文本 代码 · 共 30 行

TXT
30
字号
  例11.3指向结构体变量的指针的应用。
#include <string.h>
main()
    {struct student
          {long num;
            char name[20];
            char sex;
            float score;
           };
        struct student stu-1;
        struct student * p;
        p=&stu-1;
        stu-1.num=89101;
        strcpy(stu-1.name,"Li Lin");
        stu-1.sex='M';
        stu-1.score=89.5;
        printf("No.:%ld\nname:%s\nsex:%c\nscore:%f\n",stu-1.num,stu-1.name,stu-1.sex,stu-1.score);
        printf("No.:%ld\nname:%s\nsex:%c\nscore:%f\n",(*p).num,(*p).name,(*p).sex, (*p).score);
        }


程序运行结果如下:
No.:89101       
  name:Li Lin        
  sex:M                     
score:89.500000
No:89101
name:Li Lin
    sex:M
score:89.500000

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?