C Language Multiple Choice Questions - Control Structure

 Following are the multiple choice questions and answers on C language Control structure that includes decision, Looping and jumping control structure.

1) What will be the output of following program ?
        #include<stdio.h>
        int main( )
        {
             int a=300,b,c;
             if(a>=400)
                 b=300;
                 c=200;
                    printf("%d,%d\n",b,c);
             return 0;
        } 
  1. Garbage value, Garbage Value
  2. 300,200
  3. 200,300
  4. Garbage value,200
Show/Hide Answer
Answer = D 
Explanation: As the condition within the if statement is false so the value of b will not be initialized so it will print the garbage value and c is initialized to 200 so the output will be Garbage,200
2) What will be the output of following code ?
      #include<stdio.h>
      int main( )
      {
          int x=10,y=20;
          if(x = = y)
               printf("%d%d",x,y);
         return 0;
      } 
  1. Garbage values
  2. Raise an error
  3. Prints Nothing
  4. None of above
Show/Hide Answer
Answer = C 
Explanation:As the condition of if statement is not true, so the statement immediately after if that is print statement will not be executed and the code prints nothing.
3)  Give the output of following code ?
      #include<stdio.h>
      int main( )
     {
          int x=3;
          float y=3.0;
          if(x = = y)
                printf(" x and y are equal");
         else
                printf(" x and y are not equal");
     } 
  1. x and y are equal
  2. x and y are not equal
  3. x and y are same
  4. None of above
Show/Hide Answer
Answer = A
4) What will be the output of code ?
      #include<stdio.h>
      int main( )
      {
             int x=3,y,z;
             y=x=10;
             z=x<10;
             printf("x=%dy=%dz=%d\n",x,y,z);
             return 0;
       } 
  1. 10,10,10
  2. 10,10,0
  3. 0,0,0
  4. 0,10,10
Show/Hide Answer
Answer = B
5) What will be the output ?
         #include<stdio.h>
         int main( )
         {
              int k=35;
              printf("%d%d%d",k==35,k=50,k>40);
         } 
  1. 35,50,40
  2. 0,50,0
  3. 0,0,0
  4. 1,1,1
Show/Hide Answer
Answer =B
6) Which of the following statement is used to take the control to the beginning of the loop ?
  1. exit
  2. break
  3. continue
  4. None of these
Show/Hide Answer
Answer = C
7) A do - while loop is useful when we want that the statement within the loop must be executed ?
  1. only once
  2. at least once
  3. more than once
  4. None of above
Show/Hide Answer
Answer = B
8) What will the output of following program ?
    #include<stdio.h>
    void main( )
    {
         int i=0;
         for(;i;)
            printf("Allquiz");
    } 
  1. Prints Nothing
  2. Raise an error
  3. Garbage value
  4. Allquiz
Show/Hide Answer
Answer = A
9) What will be the output of following program ?
      #include<stdio.h>
      void main( )
      { 
           int i;
           for(i=1;i<=5;printf("%d",i));
               i++
       }
          
  1. Error
  2. Garbage values
  3. 1 to 5
  4. Infinite loop
Show/Hide Answer
Answer =D
10) What will be the output of following program ?
           #include<stdio.h>
           int main( )
           {
               int x=4;
               while(x==1)
               {
                    x=x-1;
                    printf("%d",x);
                    x--;
               }
            } 
  1. 4
  2. 1,2,3,4
  3. Prints Nothing
  4. None of above
Show/Hide Answer
Answer =C


Do You Like This? Please take 5 seconds to share with your firends.

0 comments:

Post a Comment