nested printfs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dasarisrikar
    New Member
    • Sep 2006
    • 18

    nested printfs

    Hi,i hav executed the following c code...the inner printf executes first to print some garbage value...why dont the outer printf prints anything.....
    I got only one garbage value ..y dont two garbage values...wt is the order of precedence in printf function and in nested printfs.

    the c code is:

    void main()
    {
    while(1)
    {

    if(printf("%d", printf("%d")))
    break;
    else
    continue;
    }
    }

    Thanks & Regards
  • vimase
    New Member
    • Oct 2006
    • 5

    #2
    Originally posted by dasarisrikar
    Hi,i hav executed the following c code...the inner printf executes first to print some garbage value...why dont the outer printf prints anything.....
    I got only one garbage value ..y dont two garbage values...wt is the order of precedence in printf function and in nested printfs.

    the c code is:

    void main()
    {
    while(1)
    {

    if(printf("%d", printf("%d")))
    break;
    else
    continue;
    }
    }

    Thanks & Regards

    try executing the following code,
    Code:
    #include <stdio.h>
    int main()
    {
    while(1)
    {
    
    if(printf("%d",printf("%d ")))
    break;
    else
    continue;
    }
    return 0;
    }
    you have missed out the space in the inner printf, so the two integers are bieng printed together without space in between them.

    Comment

    • dtimes6
      New Member
      • Oct 2006
      • 73

      #3
      U may try it like this:
      Code:
      #include <stdio.h>
      int main()
      {
      	while(1)
      	{
      		if(printf("A%d\n",printf("B%d\n")))
      			break;
      		else
      			continue;
      	}
      }

      Comment

      • dasarisrikar
        New Member
        • Sep 2006
        • 18

        #4
        Thanku fnds....u r right.....

        Comment

        Working...