zoukankan      html  css  js  c++  java
  • 结构体与typedef的使用,还有结构体指针的使用(二层结构体指针)

    该类容摘抄自以下链接,为学习之后的记录,不是鄙人原创。

    学习链接:https://blog.csdn.net/a2013126370/article/details/78230890

         typedef struct
                    {
                        ...
                        ...
                    }POINT,*POINT_P;

         POINT为结构名,这个名字主要是为了在结构体中包含自己为成员变量的时候有用
                    POINT_T为struct  POINT的别名
                    POINT_P为struct  POINT*的别名

                    POINT为结构体名,可声明对象;
                    POINT_P为struct  POINT*的别名,等同于typedef POINT * POINT_P;

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

            #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

  • 相关阅读:
    python json模块(15)
    python random模块(14)
    python time模块(13)
    python sys模块(12)
    python zip函数(11)
    python递归函数(10)
    python 浅拷贝和深拷贝(9)
    python is 和 == 区别(8)
    python 可变数据类型和不可变数据类型(7)
    python局部变量和全局变量(6)
  • 原文地址:https://www.cnblogs.com/854594834-YT/p/10105018.html
Copyright © 2011-2022 走看看