Like us on google+

Sunday, 20 October 2013

Widgets

PRINTF INSIDE ANOTHER PRINTF STATEMENT

#include<stdio.h>
int main()
{
  int num=2222;

  printf("%d",printf("%d",printf("%d",num)));

  return 0;
}

----------------------------------------------------
Sample Output:222241

Step 1: First the inner printf is executed 2222 is printed.
        i.e: printf("%d",num)
        
Step 2:Inner printf returns the number of digits to the             second inner printf.
       Second inner printf looks like
       printf("%d",printf("%d",num))
       
Step 3:Now Second inner printf prints 4 and returns number        of digits to the outer printf.
      (4 is single digit hence 1 is returned to the outer          printf)

Step4: Final Output:222241
-----------------------------------------------------
Key point that one must remember is inner printf returns the length of the string printed on the screen to the outer printf..

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
About us:
Hi guys Sandesh and Rajesh here ... studing engineering in PESIT started this blog as a google contest and also we love blogging ...Hope u like it ...Encourage us by liking us on g+... Any queries dont hesitate to ask Read More →

0 comments: