Nested printf (printf inside printf) in C Last Updated : 13 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Predict the output of the following C program with a printf inside printf. C #include<stdio.h> int main() { int x = 1987; printf("%d", printf("%d", printf("%d", x))); return(0); } Output : 198741 Explanation : 1. Firstly, the innermost printf is executed which results in printing 1987 2. This printf returns total number of digits in 1987 i.e 4. printf() returns number of characters successfully printed on screen. The whole statement reduces to : C printf("%d", printf("%d", 4)); 3. The second printf then prints 4 and returns the total number of digits in 4 i.e 1 (4 is single digit number ). 4. Finally, the whole statement simply reduces to : C printf("%d", 1); 5. It simply prints 1 and output will be : Output: 198741 So, when multiple printf's appear inside another printf, the inner printf prints its output and returns length of the string printed on the screen to the outer printf. Comment More infoAdvertise with us Next Article Nested printf (printf inside printf) in C K kartik Improve Article Tags : C Language c-input-output C-Input and Output Quiz Similar Reads What is the difference between printf, sprintf and fprintf? The printf() function is used as a standard method for output operations and C also provides some different versions of this function such as sprintf() and fprintf(). These functions are also used for output operations but in different contexts.The below table lists the primary differences between t 3 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 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 What is use of %n in printf() ? In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n. C #include<stdio.h> int 1 min read Use of & in scanf() but not in printf() Why there is need of using '&' in case of scanf function while not in case of printf function. Examples: scanf("%d %d", &a, &b);printf("%d %d", a, b);As a and b above are two variable and each has their own address assigned but instead of a and b, we send the address of a and b respectiv 1 min read Like