预处理
来源:互联网 发布:郎酒 知乎 编辑:程序博客网 时间:2024/05/22 01:53
1.宏定义用双引号括起来将失去作用
如#define PI 3.14
若在main函数中使用,printf(“PI”);输出的将是PI
2.#define #undef取消宏定义,
3.与typedef差别:
#define char* PIN1
typedef char* PIN2;
PIN1 x,y; // char *x,y;
PIN2 a,b;//char *a,*b;
4.不用循环和递归,打印数字0...99
#include <stdio.h>
#define A(x) x;x;x;x;x;x;x;x;x;x;
#define FORMAT1 "%d\n"
void main()
{
int n = 0;
A(A( printf(FORMAT1,n++) ));
}
5.带参数的宏定义
#define M(y) y*y + 3 *y //宏定义
k = M(5); //宏调用
example1:
#include <stdio.h>
#define FORMAT1 "%d\n"
#define MAX(a,b) (a>b)?a:b
void main()
{
int max = 0;
max = MAX(2,4);
printf(FORMAT1,max);
}
example2:
#include <stdio.h>
//#define SQ(y) y * y //b = 5
#define SQ(y) (y) * (y) //b = 9,c = 180
//#define SQ(y) ( (y) * (y) ) //b = 9,c = 20
void main()
{
int a,b,c;
a = 2;
b = SQ(a + 1);
c = 180 / SQ(a + 1);
printf("%d\n%d\n",b,c);
}
6.条件编译
#ifdef
#else
#endif
#ifndef
#define
#else
#endif
#if
#else
#endif
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 预处理
- 【C/C++】内存对齐
- 温度场有限容积法程序入门之六:后处理.花絮.Contour Plotter and 3D Function Grapher Together - the Applet and the Souce Co
- Rounded Numbers
- Luence中文分词的简单例子
- 23种-----Java设计模式
- 预处理
- AS3单例模式(Singleton)
- 多处最优服务次序问题
- Objective-C中的字符串格式化输出
- C++从入门到精通 总结一:面向过程的程序设计
- Java IO流学习总结
- Decimal to Binary
- 9i10g11g编程艺术——索引
- Java调用C和C++函数时的JNI使用区别