#includeint main() { printf("%sn",__TIME__); printf("%dn",__LINE__); printf("%sn",__DATE__); printf("%sn",__TIME__); }
#include#define SWAP(T,x,y) {T t=x;x=y;y=t;} int main() { int a=1,b=2; double c=1.1,d =2.2; SWAP(int, a,b); SWAP(double,c,d); return 0; }
#include#define Pi 3.14 #define S(r) Pi*(r)*(r) int main() { printf("%g",S(2)); return 0; }
#include#define MAX(x,y) ((x)>(y)?(x):(y))//remember the braces int main() { int a =1,b=2; int c =3,d =4; printf("%dn",MAX(a,b)+MAX(c,d)); return 0; }
#include#define STR(x) puts(#x) int main() { STR(hello);//puts("hello") return 0; }
#include#define P(XXXXX) print##XXXXX()//##replace the string void printhello(){ printf("hello n"); } void printworld(){ printf("world n"); } int main() { P(hello);//printhello() P(world);//printworld() return 0; }
C语言#if、##ifdef、#ifndef的用法详解,C语言条件编译详解
宏定义来实现条件编译(#define #undef #ifdef)_麒麒川的博客-CSDN博客_宏定义条件编译
#include#ifndef varX #define varX 1 int x =10000; #endif #ifdef varX #undef varX//cancel define varX #endif #ifndef varX #define varX 2 //int X =10086;//cause conflict #endif int main() { printf("%d n",x); printf("%d n",varX); return 0; }



