如何更改main()中printf()的输出?
在这里,我们将看到如何从main()更改printf()函数的输出。在这里,我们将定义一个函数,该函数会将给定类型的所有printf()语句更改为另一种类型。
我们将使用#define宏执行此任务。该宏将在函数内部定义。我们可以直接在函数中使用#define行而不使用它,但是在那种情况下,总是会更改printf()。要使用main控制它,我们必须先调用该函数。
示例
#include <stdio.h>
void changePrintf() { //always any printf will print 50
#define printf(x, y) printf(x, 50);
}
main() {
int x = 40;
changePrintf();
printf("%d\n", x);
x = 60;
printf("%d", x);
}输出结果
50 50
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短