【c程序】关于宏
2015-08-30 15:59
381 查看
/******************************************************/ /**************---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 1 int 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() { H I int 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; }
相关文章推荐
- iOS: ARC和非ARC下使用Block属性的问题
- Linux网络栈剖析—从socket到设备驱动程序
- C#软件winform程序安装包制作
- 第二章 创建和销毁对象(上)
- Error Handling
- hdu 5423 统计树每一层的节点树 dfs
- 鸡兔同笼
- iOS 状态栏(UIStatusBar)的相关设置
- [HDOJ1754]I Hate It
- 插入排序
- PhantomJS简介
- 面试题5:从尾到头打印链表
- 关于js的Array.prototype.slice.call
- 多线程与RunLoop
- java输入输出流
- Recommending music on Spotify with deep learning 采用深度学习算法为Spotify做基于内容的音乐推荐
- 面试题29.数组中出现次数超过一半的数字
- 如何使用贝瑟尔曲线切的圆角 Button
- AddressBook/AddressBookUI
- 了解FTP