Home  >  Article  >  Backend Development  >  How to change the output of printf() function in main() function?

How to change the output of printf() function in main() function?

王林
王林forward
2023-09-03 09:17:061056browse

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.

Example

#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);
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete