Home > Backend Development > C++ > body text

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

王林
Release: 2023-09-03 09:17:06
forward
1104 people have browsed it

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);
}
Copy after login

Output

50
50
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!