首页 > 其他 > 详细

结构体、指针

时间:2015-12-28 12:19:36      阅读:172      评论:0      收藏:0      [点我收藏+]

①struct  StudentRec           //①声明结构体类型StudentRec
{  
      char StuNum[20];        //②定义结构体的成员变量
      char StuName[20];      //②
      int Score1;                   //②
      int Score2;                   //②
      int Admit;                     //②
} ;

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

strcpy(stu1.StuNum,  "0001");  
    strcpy(stu1.StuName, "Zhangsan");       // Dot “.” is called the member selection operator。。。。用在非指针那里
    stu1.Score1 = 90;
    stu1.Score2 = 100;
    stu1.Admit  = 1;

 

 

②struct  StudentRec          
{  
    char StuNum[20];
    char StuName[20];
    int Score1;                  
    int Score2;                  
    int Admit;                
} ;

int main()
{
     struct studentRec Stu;
     struct studentRec* pStu;                   
     pStu = &Stu;

    strcpy( Stu.num, “1000” );                //.用在非指针类型
    strcpy( Stu.name, "Linda" ); 
    Stu.Score1 = 89;                                 
   //or
    strcpy( pStu->num, “1000” );      //->用在指针类型。两者等价
    strcpy( pStu->num, “Linda”;
    pStu->Sccore1 =89;
}

 

③struct  students
{  
     char StuNum[20];   
     char StuName[20];  
     int Score1;       
     int Score2;       
     bool Admit;       
} stu1, stu2;         //定义结构体变量stu1,stu2

 

④设指针

struct NODE {
 int element;   // 存放堆栈的元素
 struct NODE* link;            // 指向下一个结点的指针
};

结构体、指针

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

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