/******************************************************//**************---about Macro----------**************// ---author:tibruce Zhao---**************//**************---date:2015/7/31------**************//*** /#include <iostream> #include <stdio.h>//this is Macro. #define PI 3.1415926//#define H printf ("Hello,the world!\n");//sign "\" for continuation character # define I int n;printf ("Please enter an integer:"); scanf ("%d", &n);p rintf ("you entered half of%d \ n", n+n), using namespace std; #ifndef h//if not defined h#define H cout<< "Hello,the Chain !!" <<endl; #else # define __h H #undef H//Cancel the definition of H. #-H "* * *" #endif//Standard Model #ifndef vx#define VX 1int x=3; #endif//Definition functions, macro functions. #define SWAP (t,x,y) {T t=x;x=y;y=t;} #define MAX (x, y) x<y?y:x#define STR (x) puts (#x)//"#" changes the argument to the corresponding string void Welcomestudent () {printf ("Welcome fellow students \ \");} void Welcomestudent () {STR (welcome fellow students);} void Welcometeacher () {printf ("Welcome to teachers \ \");} #define Welcome (WHO) welcome# #who ()//# #用于拼接int main () {HiintA=10,b=20;double c=12.3,d=45.6; SWAP (int,a,b);//{t t=x;x=y;y=t;} SWAP (double,c,d);p rintf ("a=%d,b=%d\n", A, b);p rintf ("c=%g,d=%g\n", C,d);p rintf ("%d\n", MAX (b)),//printf ("%d\n", MAX (++a,++b));//macro function preferably without such operator (+ +) cout<< "*******************************************" <<endl; STR ("Hello,the world!"); Welcome (student); welcome (teacher); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"C + + programs" about macros