macro函数
We can use printf() function in a Macro. In this example, we are creating a function like Macro that will print the result of a calculation, like adding two numbers.
我们可以在宏中使用printf()函数。 在此示例中,我们将创建一个类似于Macro的函数 ,该函数将打印计算结果 ,例如将两个数字相加。
Macro definition:
宏定义:
#define SUM(a,b) (printf("SUM of %d and %d is = %d\n", a, b, a+b))
Example:
例:
#include <stdio.h>
#define SUM(a,b) (printf("SUM of %d and %d is = %d\n", a, b, a+b))
//Main code
int main(){
//adding 10 and 20
SUM(10,20);
//adfing 100 and 200
SUM(100,200);
return 0;
}
Output
输出量
SUM of 10 and 20 is = 30
SUM of 100 and 200 is = 300
翻译自: https://www.includehelp.com/c-programs/define-a-function-like-macro-that-should-use-printf-in-c.aspx
macro函数