TCS Technical MCQs

Questions 11: Predict the output of the following code :

#include < stdio.h >
int main(){
    int a=10,b=0;
    while(a>=b)
    {
     a=a-1;
     printf("%d",a);
     }
return 0;
}

  • Options
  • a : 9 8 7 6 5 4 3 2 1
  • b : 9 8 7 6 5 4 3 2 1 0
  • c : 9 8 7 6 5 4 3 2 1 0 -1
  • d : 10 8 7 6 5 4 3 2 1 0
  • Answer: c) 9 8 7 6 5 4 3 2 1 0 -1

    Questions 12: What will be the output of the following code?

    #include < stdio.h >
    int main(){
       int y=1,x;
       for(x=0;x<=2;x++){
          while(y < 3)
          {
           printf(" %d",x+y);
           y++;
           }
        }
    return 0;
    }
    

  • Options
  • a : 1 2 3
  • b : 1
  • c : 2
  • d : 1 2
  • Answer: d) 1 2

    Questions 13: What will be the output of the following code?

    #include < stdio.h >
    int main(){
    int n=1,r=3,c;
       for(c=1;c < =r;c++)
          n=n*c;
       printf("%d",n);
    return 0;
    }     
    

  • Options
  • a : 3
  • b : 6
  • c : 2
  • d : Compilation Error
  • Answer: b) 6

    Questions 14: What will be the output of the following code?

    #include < stdio.h >
    int main(){
     int y=2,z=4;
     printf("%d ",(y || z) && (z || y));
    return 0;
    } 
    

  • Options
  • a : 0
  • b : 1
  • c : 2
  • d : 4
  • Answer: b) 1

    Questions 15: What will be the output of the following code?

    #include < stdio.h >
    int main(){
    int x=7;
        float y=7.0; 
        if ( x==y )
           printf("Equal");
         else
           printf("Unequal");
    return 0;
    }  
    

  • Options
  • a : Equal
  • b : Unequal
  • c : Compilation error
  • d : None of the above
  • Answer: a) Equal

    Questions 16: What will be the output of the following code?

    #include < stdio.h >
    int main(){
        int arr[]={3,7,18,9,5};
        int result = ++arr[3];
        printf("%d",result);
    return 0;
    }
    

  • Options
  • a : 9
  • b : 10
  • c : 18
  • d : Error
  • Answer: b) 10

    Questions 17: What will be the output of the following code ?

    #include < stdio.h >
    int main(){
     int no = 2357;
     float amount = 125.00;
      while(no>0) 
      {
      if((amount >100.00) &&
        (amount <=125.00))
       printf("Discount is 50%");
      else
         printf("Discount is 30%");
       }
    return 0;
    }                   
        

  • Options
  • a : Discount is 50% will be displayed infinitly
  • b : Discount is 30% will be displayed infinitly
  • c : No output
  • d : Error
  • Answer: a) Discount is 50% will be displayed infinitly

    Questions 18: What will be the output of the following question?

    #include < stdio.h >
    int main(){
     int n = 10;
     for (int index = 0;index<=5;index++)
        n = n * index;
        printf("%d",n);
    return 0;
    }         
    

  • Options
  • a : 0
  • b : 1200
  • c : 240
  • d : None of the above
  • Answer: a) 0

    Questions 19: How many will following loop take to find key = 37 in array?

    #include < stdio.h >
    int main()
    {
    int key=37;
    int c=0;
       int array[]={27,17,47,37,67};
       for (int ele = 0; ele<=4;ele++){
           if ( array[ele]== key){
           printf("found");
           break;
           }
         }
    return 0;
    }     
    

  • Options
  • a : 5
  • b : 4
  • c : infinite loop
  • d : no iteration
  • Answer: b) 4

    Questions 20: What will be the output of the following code?

    #include < stdio.h >
    int main(){
       int Mark=90;
       int Flag;
       while(Mark>=0){
           if(Mark>100){
             printf("Invalid Mark");
             Flag = 0;
             }
            else
           {
            printf("Valid Mark");
            Flag = 1;
            }
        }
    return 0;
    }
    

  • Options
  • a : Invalid Mark will be displayed infinitly
  • b : Valid Mark will be displayed infinitly
  • c : No output
  • d : Error
  • Answer: b) Valid Mark will be displayed infinitly

    TCS

    If you find any question wrong, please send your solution to [email protected]