What happens when you use a printf() function inside another printf() function.
To understand this lets see the following example:
#include<stdio.h>
int main() {
int number = 1234;
printf("%d", printf("%d", printf("%d", number)));
return(0);
}
Output:
123441
Explanation of the above program::
The "innermost" printf() function prints the value of the number i.e., "1234"
The second printf() function will now be as
printf("%d", 4);
it's because the first printf() function will return 4 as the total number of digits in original "number" and it will print "4".
The output will now be "12344"
The last printf() fiunction will now be as
printf("%d", 1);
it's because the second printf() function will return 1 as the total number of digits(i.e., 4 is a single digit number) and it will print "1".
The output will now be "123441".
0 Comment(s)