what can be the o/p of following code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sehgal490
    New Member
    • Jan 2010
    • 3

    what can be the o/p of following code?

    Code:
    void main()
    {
      int i;
      for(i=1;i<4,i++)                                                                                 
      switch(i)
      case 1: printf("%d",i);break;
    {
     case 2:printf("%d",i);break;
     case 3:printf("%d",i);break;
    }
     switch(i) case 4:printf("%d",i);
    }
  • Airslash
    New Member
    • Nov 2007
    • 221

    #2
    sounds like homework to me.....

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      compile error around switch.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        The open-brace immediately below the case 1 statement belongs one line higher, between the switch(i) and case 1 statements. Was this simply a typo in your post or are you intentionally exploring what happens for atypical syntax?

        Comment

        • sehgal490
          New Member
          • Jan 2010
          • 3

          #5
          Ya, it is an error...i checked it on the turbo c but the answer is 1234........acc ording to the company test

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            First off use CODE tags!!!

            Second, please format your code better. If you put a proper format around your code some of the issues will become clear.

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              So you're getting an answer ("1234"). Do you have any reason to believe this is the wrong answer? Do you want to understand why that result occurred?

              Comment

              • sehgal490
                New Member
                • Jan 2010
                • 3

                #8
                yeah.... i want to understand this simple looking code

                Comment

                Working...