终于弄明白了的结构体与typedef的使用,还有结构体指针的使用(二层结构体指针)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a2013126370/article/details/78230890
 *  结构体与typedef]

                c语言规范,定义结构体:
                typedef  struct POINT
                {
                    ...
                    ...
                }POINT_T, *POINT_P;
     
                POINT为结构名,这个名字主要是为了在结构体中包含自己为成员变量的时候有用
                POINT_T为struct  POINT的别名
                POINT_P为struct  POINT*的别名
     
                上面的定义方式等价于
     
                struct POINT
                {
                    ...
                    ...
                };
                typedef  struct POINT POINT_T;
                typedef  struct POINT *POINT_P;
        
                typedef struct
                {
                    ...
                    ...
                }POINT,*POINT_P;
                POINT为结构体名,可声明对象;
                POINT_P为struct  POINT*的别名,等同于typedef POINT * POINT_P;
            

    相关网址:http://blog.sina.com.cn/s/blog_5f70c7060101201e.html

http://blog.sina.com.cn/s/blog_4fdabc820100fsxu.html

结构体指针如何使用(二层指针)

        #include <iostream>
        using namespace std;
        typedef struct {
        int x;
        int y;
        }point,*_point; //定义类,给类一个别名
        //验证 typedef point * _point;
        int main()
        {
            _point *hp;
            point pt1;
            pt1.x = 2;
            pt1.y = 5;
            _point p;
            p = &pt1;
            hp = &p;

            cout<<  pt1.x<<" "<<pt1.y <<endl;
            cout<< (**hp).x <<" "<< (**hp).y <<endl;
            return 0;
        }
        
        //运行结果:2 5
                       2 5

猜你喜欢

转载自blog.csdn.net/a2013126370/article/details/78230890