【c程序】关于宏

来源:互联网 发布:淘宝卖家找货源网 编辑:程序博客网 时间:2024/05/13 20:14
/******************************************************//**************---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");//符号"\"为续行符#define I\    int n;\printf("请输入一个整数:");\scanf("%d",&n);\printf("你输入的是%d的一半\n",n+n);using namespace std;#ifndef H//如果没定义H#define H cout<<"Hello,the Chain!!"<<endl;#else#define __H H   #undef  H   //取消对H的定义#define H "***"#endif//标准模型#ifndef VX#define VX 1int x=3;#endif//定义函数,宏函数。#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)//“#”把参数变为对应的字符串void welcomestudent(){printf("欢迎各位同学 \n");}void welcomestudent(){STR(欢迎各位同学);}void welcometeacher(){printf("欢迎各位老师 \n");}#define welcome(who) welcome##who()  //##用于拼接int main(){HIint a=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);printf("a=%d,b=%d\n",a,b);printf("c=%g,d=%g\n",c,d);printf("%d\n",MAX(a,b));//printf("%d\n",MAX(++a,++b));//宏函数最好不用这样的运算符(++)cout<<"*******************************************"<<endl;STR("HELLO,THE WORLD!");welcome(student);welcome(teacher);return 0;}

0 0
原创粉丝点击