C十四:结构体

1 首先://注意在C和C++里不同
    在C中定义一个结构体类型要用typedef:
    typedef struct Student
    {
    int a;
    }Stu;

    于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student stu1;来声明)
    这里的Stu实际上就是struct Student的别名。Stu==struct Student


    另外这里也可以不写Student(于是也不能struct Student stu1;了,必须是Stu stu1;)
    typedef struct
    {
    int a;
    }Stu;


    但在c++里很简单,直接
    struct Student
    {
    int a;

    };    
    于是就定义了结构体类型Student,声明变量时直接Student stu2;


typedef int arrs[5];

typedef arrs * p_arr5;

typedef p_arr5 arrp10[10];

arr5 togs; // togs是具有5个元素的int数组

p_arr5 p2; // p2是一个指针,指向具有元素的数组

arrp10 ap; // ap是具有十个元素的指针数组,每个指针指向具有5个元素的int数组 

猜你喜欢

转载自blog.csdn.net/m0_37564426/article/details/83008677