Macro Substitution – 2.c

Preprocessing functions commonly used are mainly provided by the C language ; the macro definition file contains conditional compilation
对 #define 用法的几点说明

  1. 宏定义是用宏名来表示一个字符串,在宏展开时又以该字符串取代宏名,这只是一种简单粗暴的替换。字符串中可以含任何字符,它可以是常数、表达式、if 语句、函数等,预处理程序对它不作任何检查,如有错误,只能在编译已被宏展开后的源程序时发现。

  2. 宏定义不是说明或语句,在行末不必加分号,如加上分号则连分号也一起替换。

  3. 宏定义必须写在函数之外,其作用域为宏定义命令起到源程序结束。如要终止其作用域可使用#undef命令。

猜猜下面这个程序输出什么!!!

#include <stdio.h>
#define A 1+2
#define B 3+4
int main(void)
{
	int var=A*B;
	printf("%d\n",var);
	return 0;
}
发布了52 篇原创文章 · 获赞 25 · 访问量 1286

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/104849691