代码实例:#include
#define MAX_ARRAY_LENGTH 20
#define FILE_SIZE 84
#undef FILE_SIZE
#define FILE_SIZE 42
#ifndef DOMAIN
#define DOMAIN "www.what21.com"
#endif
//defined() 运算符
#if !defined (MESSAGE)
#define MESSAGE "www.what21.com~!"
#endif
//标记粘贴运算符(##)
#define pasterToken(n) printf("token" #n " = %d\n", token##n)
//参数化的宏
#define MAX(x,y) ((x) > (y) ? (x) : (y))
/**
主函数
@param argc argc description
@param argv argv description
@return return value description
*/
int main(int argc,const char* argv[]){
printf("%d\n",MAX_ARRAY_LENGTH);
printf("%d\n",FILE_SIZE);
printf("%s\n",DOMAIN);
//字符串常量化运算符(#)和标记粘贴运算符(##)。
int token34 = 40;
pasterToken(34);
printf("%s\n", MESSAGE);
printf("Max between 20 and 10 is %d\n", MAX(10, 20));
printf("File :%s\n", __FILE__ );
printf("Date :%s\n", __DATE__ );
printf("Time :%s\n", __TIME__ );
printf("Line :%d\n", __LINE__ );
printf("ANSI :%d\n", __STDC__ );
return 0;
}