美文网首页十天学会C语言程序员
C语言day10-11typedef和宏定义区别

C语言day10-11typedef和宏定义区别

作者: liyuhong165 | 来源:发表于2016-05-09 01:32 被阅读79次

    pragma mark typedef和宏定义区别

    pragma mark 概念

    pragma mark 代码

    #include <stdio.h>
    typedef int myInt;
    #define Integer int
    
    typedef char * String;
    #define MY_STRING char *
    // 一般情况下如果要给数据类型起一个名建议用typedef, 不要用define
    
    int main()
    {
        /*
        int num = 10;
        printf("num = %i\n",num);
        
        myInt age = 22;
        printf("num = %i\n",age);
    
        Integer score = 100;
        printf("score = %i\n",score);
         */
        
        /*
        char *name = "lyh";
        printf("name = %s\n",name);
        
        String name2= "lys";
        printf("name2 = %s\n",name2);
        
        MY_STRING name3 = "lyx";
        printf("name3 = %s\n",name3);
         */
        
    #warning typedef做的到的 define做不到
        String name1,name2,name3;
        name1 = "lyh";
        name2 = "lys";
        printf("name1 = %s, name2 = %s\n",name1,name2);
        
    //  char *name3, name4;     // char *name3; char name4
        MY_STRING name3,name4;
        name3 = "lyh";
        name4 = "lys";
        printf("name3 = %s, name4 = %s\n",name3,name4);
        return 0;
    }
    
    

    相关文章

      网友评论

        本文标题:C语言day10-11typedef和宏定义区别

        本文链接:https://www.haomeiwen.com/subject/ffxerttx.html