Printf inside printf in C : Example 1
#include<stdio.h>
#include<conio.h>
void main()
{
int num=1342;
clrscr();
printf("%d",printf("%d",printf("%d",num)));
getch();
}
Output :
134241
How ?
- Firstly Inner printf is executed which results in printing 1324
- This Printf Returns total number of Digits i.e 4 and second inner printf will looks like
-
printf("%d",printf("%d",4)); - It prints 4 and Returns the total number of digits i.e 1 (4 is single digit number )
-
printf("%d",1); - It prints simply 1 and output will looks like 132441
Rule :
Inner printf returns Length of string printed on screen to the outer printf

