Predict the output of the following C program with a printf inside printf.
#include<stdio.h> int main() { int x = 1987; printf ( "%d" , printf ( "%d" , printf ( "%d" , x))); return (0); } Output :
|
Explanation :
1. Firstly, the innermost printf is executed which results in printing 1987
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 :
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 :
|
No comments:
Post a Comment