C语言使用技巧(一):C语言枚举类型typedef enum作为函数返回值及函数参数

源码:

#include <stdio.h>
typedef enum _TEST_enum
{
    
    
    A = 2018,
    B,
    C,
} TEST_enum;

TEST_enum MAKE(int i)
{
    
    
    if (i == 1) 
    {
    
    
        return A;
    }
    if (i == 2)
    {
    
    
        return B;
    }
    if (i == 3)
    {
    
    
        return C;
    }
}


int main()
{
    
    
    /*直接调用函数,我需再次定义结构体*/
    printf("MAKE=======%d \n", MAKE(3));
}

执行结果:

MAKE=======2020
[Thread 18272.0x6990 exited with code 17]
[Inferior 1 (process 18272) exited with code 021]

猜你喜欢

转载自blog.csdn.net/weixin_41194129/article/details/108585708
今日推荐