十天学会C语言程序员

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

2016-05-09  本文已影响79人  liyuhong165

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

上一篇下一篇

猜你喜欢

热点阅读