zoukankan      html  css  js  c++  java
  • C-数据结构-typedef的用法

    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
    ", j);
        
        ST st2;
        st2.sid = 200;
        printf("%d
    ", 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
    ", 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
    ", ps->sid);
        
        return 0;
    }
  • 相关阅读:
    超神头文件
    世界上还有比二分更容易错的算法吗?
    【POJ 1734】Sightseeing trip
    P1303 A*B Problem
    P1601 A+B Problem(高精)
    P1051 谁拿了最多奖学金
    【P1025】数的划分
    P1005 矩阵取数游戏
    P1006 传纸条
    邮票问题
  • 原文地址:https://www.cnblogs.com/LXL616/p/10635608.html
Copyright © 2011-2022 走看看