C经典 typedof的使用方法

#include <stdio.h>
int sum(int a, int b){
    return  a + b;
}
int reduce(int a , int b){
    return  a - b;
}
int main(int argc, const char * argv[])
{

    // 1。基本类型
    typedef int NINT;
    NINT a = 5;

    // 2。数组
    typedef int ARRAY[5];
    ARRAY a1= {1,2,3,4,5},b1= {1,2,3,4,5};// == int a1[5],b1[5]
    for (int i = 0; i < 5; i ++) {
        printf("%d\t",a1[i]);
    }
    printf("\n");
    // 3.1结构体
    struct Person{
        int age;
        char *name;
    };
    struct Person p1={22,"tom"};
    typedef struct Person P;
    P p2 = {33,"smith"};
    printf("%s\n", p2.name);

    // 3.2结构体
    typedef struct Car{
        int speed;
        char *name;
    }MYCAR;

    MYCAR c = {33,"great wall"};
    printf("%s\n", c.name);

    // 3.3结构体
    typedef struct{
        int speed;
        char *name;
    }MAN;

    MAN m = {33,"li ming"};
    printf("%s\n", m.name);

    //4.枚举类型
    typedef enum Sex{kMAN,kWOMEN,kOTHER} ISEX;
    typedef enum {kONE,kTWO,kTHREE} WEEK;

    ISEX s1,s2;
    s1 = kMAN;
    printf("%d\n",s1); //=0

    //5.函数指针
    int (*p)(int,int);
    typedef int (*PFUN)(int,int);
    PFUN pa, pb;
    pa = sum;
    pb = reduce;
    printf("%d %d",pa(2,2),pb(2,3));

    printf("\n");
    return 0;
}
发布了544 篇原创文章 · 获赞 133 · 访问量 106万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览