C Program to Demonstrate Printf inside Another Printf Statement
Printf inside printf in C : Example 1
1 2 3 4 5 6 7 | #include<stdio.h> int main() { int num = 1342; printf("%d", printf("%d", printf("%d", num))); return(0); } |
Output :
1 | 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
- 1printf("%d",printf("%d",4));
- It prints 4 and Returns the total number of digits i.e 1 (4 is single digit number )
- 1printf("%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