Home > Article > Backend Development > How to change the output of printf() function in main() function?
Here we will see how to change the output of the printf() function in main(). Here we will define a function that will change all printf() statements of a given type to another type.
We will use the #define macro to accomplish this task. This macro will be defined inside the function. We can place the #define line directly without using it in the function, but in this case printf() will always be changed. To control it using main we must first call the function.
#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</p><p>", x); x = 60; printf("%d", x); }
50 50
The above is the detailed content of How to change the output of printf() function in main() function?. For more information, please follow other related articles on the PHP Chinese website!