C++语言复习八 结构体指针(指向类的指针)的两种引用方式。

来源:互联网 发布:环保监测数据 编辑:程序博客网 时间:2024/05/24 20:06

结构体指针(指向类的指针)的两种引用方式。

例:

#include<iostream>using namespace std;struct student{int Nomclass;int Nomage;};void main(){struct student stu1;struct student *p_stu = &stu1;(*p_stu).Nomclass= 120101;//结构体指针取结构体成员的第一种方式。p_stu->Nomage= 23;//结构体指针取结构体成员的第二种方式。cout<<stu1.Nomclass//结构体变量取结构体成员的第一种方式。<<"  "<<(&stu1)->Nomage//结构体变量取结构体成员的第二种方式。<<endl;}








原创粉丝点击