Monday, August 31, 2009

AMSWER (1) : TO EXECUTE BOTH IF - ELSE BLOCKS

THE ANSWER FOR THE CHALLENGE (1) IS:

------------------------------------------------------------------------------




#include<...headerfiles..>


void main()
{
            if(!printf("HELLO "))
                  {
                  //some code here
                  }
           else
                {
                printf("World");
                }
}
----------------------------------------------------------------------------

EXPLANATION:
In IF block u see printf() function which actually returns how many characters it had printed successfully ., So in printf("HELLO " retruns 6(int) (5-HELLO and 1-Space) .... so Negation of 6(int) makes if statement false after printing HELLO and moves the control to ELSE block where another print statement Executes normally....

No comments:

Post a Comment