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

CServer Side ProgrammingProgramming

Here we will see how to change the output of the printf() function from main(). Here we will define a function that will change all of the printf() statements with the given type to another type.

We will use the #define macro to do this task. This macro will be defined inside the function. We can directly put the #define line without using it in the function, but in that case always the printf() will be changed. To control it using main, we have to call the function first.


#include <stdio.h>
void changePrintf() { //always any printf will print 50
   #define printf(x, y) printf(x, 50);
main() {
   int x = 40;
", x);    x = 60;    printf("%d", x); }


Updated on 30-Jul-2019 22:30:26