How to Change the Output of printf() in main() in C? Last Updated : 21 Jun, 2022 Comments Improve Suggest changes Like Article Like Report To change the output of printf() in main(), we can use Macro Arguments. #define macro can be used for this task. This macro is defined inside the function. Although, #define can be used without declaring it in the function, in that case always the printf() will be changed. The function needs to be called first to change the output of printf() in main(). Consider the following program. Change the program so that the output of printf() is always 10. C // C Program to demonstrate changing the output of printf() // in main() #include <stdio.h> void fun() { // Add something here so that the printf in main prints // 10 } // Driver Code int main() { int i = 10; fun(); i = 20; printf("%d", i); return 0; } It is not allowed to change main(). Only fun() can be changed. Now, consider the following program using Macro Arguments, C // C Program to demonstrate the use of macro arguments to // change the output of printf() #include <stdio.h> void fun() { #define printf(x, y) printf(x, 10); } // Driver Code int main() { int i = 10; fun(); i = 20; printf("%d", i); return 0; } Output 10 Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Change the Output of printf() in main() in C? K kartik Improve Article Tags : C Language cpp-puzzle Similar Reads How to write a running C code without main()? Write a C language code that prints GeeksforGeeks without any main function. Logically it's seems impossible to write a C program without using a main() function. Since every program must have a main() function because:- It's an entry point of every C/C++ program.All Predefined and User-defined Func 2 min read Execution of printf With ++ Operators in C Consider the following statement in C and predict its output.printf("%d %d %d", i, ++i, i++);This statement invokes undefined behavior by referencing both âiâ and âi++â in the argument list.In C, the evaluation order of function arguments is not specified. It means the compiler is free to evaluate a 2 min read How to Write Your Own printf() in C? In this article, we will learn how to implement your own custom printf() function in C language. The printf() function is present in <stdio.h> header and uses a const char* and variable length arguments as its parameters. Hence we would be using <stdarg.h> header file which provides oper 4 min read How to Create Your Own scanf() in C? The scanf() function is used to take input from the console. It is defined in <stdio.h> header file and takes const char* and variable argument list as parameters. In this article, we will learn how to implement your own custom scanf() function in C language. For this, we need to have a firm g 3 min read Output of C programs | Set 40 (File handling) Prerequisite : File handling 1. What is the output of this program by manipulating the text file? C #include <stdio.h> int main() { if (remove("myfile.txt") != 0) perror("Error"); else puts("Success"); return 0; } Options: a) Error b) Success c) Runtime Error d) C 3 min read Like