20 Aug 2013

Basic level c practice controlstatement set 1



1.      main()  WIPRO

{

            int i=3;

            switch(i)

             {

                default:printf("zero");

                case 1: printf("one");

                           break;

               case 2:printf("two");

                          break;

              case 3: printf("three");

                          break;

              

}

Answer :

three

Explanation :

The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.


2.      Imp. main()  SAMSUNG

            {

            static int var = 5;

            printf("%d ",var--);

            if(var)

                        main();

            }

Answer:

5 4 3 2 1

            Explanation:

When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively. 



3 comments: