How to Change the Output of printf() in main() in C? Last Updated : 21 Jun, 2022 Comments Improve Suggest changes 46 Likes 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) Create Quiz Comment K kartik 46 Improve K kartik 46 Improve Article Tags : C Language cpp-puzzle Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like