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

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;
}

    原文作者:liyuhong165
    原文地址: https://www.jianshu.com/p/23fb0cf9d2ec
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞