typedef struct 和 struct的使用

typedef struct 和 struct的使用

//以下student是标识符(标识符是用户编程时使用的名字,对于变量、常量、函数、语句块也有名
字;),stu则为变量类型(类比intchar等),pstu相当于(int*)。
typedef struct student{
    string name;
    int age;
}stu,*pstu;
//C++中,ss为结构体类型
struct ss{
    string name;
    int age;
};
int main(){
//变量类型==struct+标识符
    //使用变量类型+结构变量名
    stu xiaoming;
    //或者使用stuct+标识符+结构变量名
    struct student zhangsan;
    //c++ struct+结构变量名
    ss lisi;
    xiaoming.name="xiaoming";
    xiaoming.age=18;
    zhangsan.name="zhangsan";
    zhangsan.age=17;
    lisi.name="lisi";
}

猜你喜欢

转载自blog.csdn.net/weixin_41127779/article/details/82023671