首页 > 其他 > 详细

p7 struct and union

时间:2016-01-04 12:58:05      阅读:253      评论:0      收藏:0      [点我收藏+]

struct  StudentRec           //①声明结构体类型StudentRec
{  
      char StuNum[20];        //②定义结构体的成员变量
      char StuName[20];      //②                  1.Dot “.” is called the member selection operator.
                                  2. After the struct type declaration, the various members can

                                  be used in your program only when they are preceded by a struct variable name and a dot.
      int Score1;                   //②
      int Score2;                   //②
      int Admit;                     //②
} ;

//用结构体类型定义变量stu1和stu2
    struct StudentRec stu1, stu2; 

  //访问结构体变量stu1中的成员
    strcpy(stu1.StuNum,  "0001");  
    strcpy(stu1.StuName, "Zhangsan");
    stu1.Score1 = 90;
    stu1.Score2 = 100;
    stu1.Admit  = 1;
    printf( "%s %s %d %d %d\n",
               stu1.StuNum, stu1.StuName,
               stu1.Score1, stu1.Score2, stu1.Admit );

 

 

struct studentRec* pStu;  

strcpy( pStu->num, “1000” );
    strcpy( pStu->num, “Linda”;
    pStu->Sccore1 =89;

p7 struct and union

原文:http://www.cnblogs.com/-lyric/p/5098326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!