Saturday, 5 July 2014

Control Instructions ( Part4 )

Control Instructions (C-FAQ's)



Q1: What is the output for the program given below?


            #include<stdio.h>

            int main()

            {

                        int x= 1, y= 2;

                        switch ( x )

                        {

                                    case 1:

                                                printf("In, Case 1\n");

                                    case y:

                                                printf("In, Case y\n");

                                                break;

                        }                               

                        return 0;

            }

 

                       

            Output:
                        Compiler will return an error because variable are not allowed in case.


Q2: Predict the output for the following code ?

          #include<stdio.h>

            int main()

            {

                        float  f = 0.5;

                        if( 0.5 > f )

                                    printf(" 0.5 is greater than f \n");

                        else

                                    printf("0.5 is equal to f \n");

                       

            return 0;

            }

 

           

            Output:        
      0.5 is equal to f 
           


Q3: What is the output of the following code?

          #include<stdio.h>

            int main()

            {

                        int i = 10, j=20;

                        if (  i=5 ) || if  (j=30 )

                                    printf(" Values has been changed\n");

                        else

                                    printf(" Nothing changed !!! \n");

                        return 0;

            }



            Output:        
        In function 'main':
        Line 5: error: expected expression before '||' token  


Q4: What is the output of the following code?


            int main()

            {

                        int loop=5;

                        while( loop-- >=0  )

                                    printf("%d",loop);

                        loop=5;

                        printf("\n");

                        while( loop-- >=0 )

                                    printf("%d",loop);

                        printf("\n");

                        while( loop-- >=0 )

                                    printf("%d",loop);

                        printf("\n");

                        return 0;

            }

 

            A.        43210-1

                        43210-1

                       


            B.        543210

                        543210


            C.        Error

            D.        543210

                        543210

                        543201

               

           


            Output:
                        A.        43210-1
                                    43210-1



<< PREV               [C FAQ's]            NEXT >>


No comments:

Post a Comment