zoukankan      html  css  js  c++  java
  • struct 与 typedef struct用法区别

    typedef struct 与 struct

    使用typedef定义结构体时,它就是类型定义的意思。主要是为了方便才使用typedef,在申请变量时可直接写例如:t_student student;

    使用struct定义构体时,只是在申请变量时,需要加上struct t_student student

    举例说明

    /* 声明st_student 结构体 */
    typedef struct st_student
    {
           char    name[64];
           int     age;
    }t_student;
    /* 申请结构体变量 */
    t_student  student;  
    
    /* 声明st_student 结构体 */
    struct st_student
    {
           char    name[64];
           int     age;
    };
    /* 申请结构体变量 */
    struct t_student  student; //必须加上strcut 
    

    对于上面使用typedef struct的代码,其实可以理解为
    定义st_student结构体别名为t_student ,通常为了简化,直接使用别名即可。

  • 相关阅读:
    [SCOI2005]栅栏
    状压dp常用操作
    [SCOI2005]互不侵犯
    欧拉函数
    hdu5179 beautiful number
    hdu4460 Friend Chains
    exgcd详解
    hdu6468 zyb的面试
    hdu1978 How many ways
    hdu1312 Red and Black
  • 原文地址:https://www.cnblogs.com/Tavi/p/12514065.html
Copyright © 2011-2022 走看看