宏定义
#include <stdio.h>
#define interger int* //只是简单的替换,相当于int*b,int c,不能执行c=b
//typedef int* interger;
int main()
{
int a=5;
interger b,c;
b=&a;
c=b;
printf("%p\n",c);
return 0;
}
[Error] invalid conversion from 'int*' to 'int' [-fpermissive]
typedef
#include <stdio.h> //#define interger int* typedef int* interger;//把int*包装为interger,相当于int*b,int*c,可以执行c=b int main() { int a=5; interger b,c; b=&a; c=b; printf("%p\n",c); return 0; }
编译通过
总结:
区别:
1.define a b 是将b用a代替,typedef a b 是将a用b代替
2.#define interger int* //只是简单的替换,相当于int*b,int c,不能执行c=b
typedef int* interger;//把int*包装为interger,相当于int*b,int*c,可以执行c=b