What will be the result of the following code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sushantvs
    New Member
    • Dec 2010
    • 1

    What will be the result of the following code?

    int x = 3;
    if (2 > x) print("First");
    else
    print("Second") ;
    if (2 > x)
    print("Third");
    print("Fourth") ;
    print("Fifth");
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Compile it and you will have your answer.

    Comment

    • Shafi hashmi
      New Member
      • Dec 2010
      • 14

      #3
      The output will be
      second
      fourth
      fifth

      coz 2 is not greater than 3 hence else part will b printed. Again 2 is not greater than 3 hence next line will not be printed but next lines will be prnted coz they are not in the 'if' block

      Comment

      Working...