第10天C语言(11):typedef和宏定义区别

二、代码
#include 

typedef int myInt;
#define Inter int
// 一般情况下 如果要给数据类型 起一个名词 建议用typedef, 不要define
typedef  char * String;
// 宏定义仅仅是替换
#define MY_STRING char *
int main()
{
    /*
    int num = 10;
    printf("num = %i\n",num);
    myInt age = 25;
    printf("age = %i\n",age);
    Inter socre = 22;
    printf("socre = %i\n",socre);
     */
    
    /*
    char *name = "lyh";
    printf("name = %s\n",name);
    
    String name1 = "lyh1";
    printf("name1 = %s\n",name1);
    
    MY_STRING name2 = "lyh2";
    printf("name2 = %s\n",name2);
     */
    
    
    String name1,name2;
    name1 = "lyh";
    name2 = "lyh1";
    printf("name1 = %s, name2 = %s\n",name1,name2);
    
// char * name3,name4; // char *name; char name4;
    MY_STRING name3,name4;
    name3 = "lyh2";
    name4 = "lyh3"; // incompatible pointer to inerger conversion assigning to char from char[5]
    
    // 访问了一个坏的内存
    printf("name3 = %s, name4 = %s\n",name3,name4);

    return 0;
}

你可能感兴趣的:(第10天C语言(11):typedef和宏定义区别)