typedef struct

#include <string>
#include <iostream>
#include "stdio.h"

using namespace std;

//结构体
struct stu{
    int age;
};

//定义一种结构体, 并设置一种别名。
typedef struct car_str {
    int price;
} *car;

//定义一种结构体类型, 并定义一个全局变量plane
struct fly {
    int price;
} plane;

int main(){

    stu s;
    s.age = 20;
    cout << s.age << endl;
    
    //定义结构体变量, 带不带sturct都可以。
    car_str cs;
    cs.price = 100;
    cout << cs.price << endl;

    struct fly boyin777;
    boyin777.price = 999;
    cout << boyin777.price << endl;

    //和#define的作用类似。
    car car1 = new car_str;
    car1->price = 200;
    cout << car1->price << endl;
    del car1;

    plane.price = 10000;
    cout << plane.price << endl;

    system("pause");


}

猜你喜欢

转载自blog.csdn.net/u013985241/article/details/82898953