首页 > 其他 > 详细

C-数据结构-typedef的用法

时间:2019-04-01 12:40:39      阅读:129      评论:0      收藏:0      [点我收藏+]
1.typedef的用法

# include <stdio.h>

typedef int zhang; //为数据类为int从新取名为zhang 等价于int
typedef struct Student
{
    int sid;
    char name[100];
    char sex;
}ST;

int main(void)
{
    int i = 10; //等价于 zhang i = 10;
    struct Student st; //等价于 ST st;
    struct Student * ps = &st; //等价于ST * ps;
    zhang j = 20;
    
    printf("%d\n", j);
    
    ST st2;
    st2.sid = 200;
    printf("%d\n", st2.sid);
    
    return 0;
}

 

2.typedef的用法2

# include <stdio.h>

typedef struct Student
{
    int sid;
    char name[100];
    char sex;
}* PST; //等价于struct Student *

int main(void)
{
    struct Student st;
    PST ps = &st;
    ps->sid = 99;
    printf("%d\n", ps->sid);
    
    return 0;
}

 

3.typedef的用法3

# include <stdio.h>

typedef struct Student
{
    int sid;
    char name[100];
    char sex;
}* PSTU, STU; //等价于STU代表了 struct Student,  PSTU 代表了struct Student * 

int main(void)
{
    STU st; //等价于 struct Student st;
    PSTU ps = &st; //等价于 struct Student * ps = &st;
    ps->sid = 99;
    
    printf("%d\n", ps->sid);
    
    return 0;
}

 

C-数据结构-typedef的用法

原文:https://www.cnblogs.com/LXL616/p/10635608.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!