TCS Technical MCQs

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

#include < stdio.h >
int  main()
  {
   const int x=5;
   const int *const p=&x;
   x++;
   printf("\n %d",x);
return 0;
}

  • Options
  • a : 5
  • b : 6
  • c : Garbage
  • d : Compile Error
  • Answer: d) Compile Error

    Questions 2: Predict the output of the following code :

    #include < stdio.h >
    int main()
    {
       int n=35;
       int i=0;
       while (n%10!=0){
         n=n+3;
         i++;
        }
        n=n+i;
        printf("%d",n);
    return 0;
    }
    

  • Options
  • a : 35
  • b : 45
  • c : 55
  • d : 65
  • Answer: c) 55

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

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

  • Options
  • a : 35
  • b : 45
  • c : 55
  • d : 65
  • Answer: a) 35

    Questions 4: Predict the output of the following code :

    #include < stdio.h >
    int main(){
       int a;
       float b=7.0;
       switch (a=b+1)
       {
        case 8: printf("TCS Digital");
             break;
         default: printf("TCS Ninja");
         }
    return 0;
    }            
    

  • Options
  • a : TCS Digital
  • b : TCS Ninja
  • c : Compile time error
  • d : Inifinte loop
  • Answer: a) TCS Digital

    Questions 5: Predict the output of the following code :

    #include < stdio.h >
    int main(){
    int number=6;
       int k=2,i=2;
       int sum=0;
       while (i<=number){
          k = k * i;                
          i = i +1 ;
        }
        printf("%d",k);
    return 0;
    }  
    

  • Options
  • a : 240
  • b : 1440
  • c : infinite loop
  • d : Compilation error
  • Answer: b) 1440

    Questions 6: How many times 'a' will be displayed on the screen?

    #include < stdio.h > 
    int main(){
      int input=25;
      while (input > 0){
      if(input > 0 && input < =10)
         printf("a");
      else if(input  >10 && input < =20)
         printf("aa");
       else if(input >20 && input <= 30)
         printf("aaa");
       input--;
       }
    return 0;
    }
    

  • Options
  • a : 25
  • b : 45
  • c : 55
  • d : None of the above
  • Answer: b) 45

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

    #include < stdio.h >
    int main(){
      int n=5,i=2;
      while(i<=n){
          printf("%d",i);
          i++;
       }
    return 0;
    }                
    

  • Options
  • a : 2 3 4
  • b : 2 3 4 5
  • c : 2 3 4 5 6
  • d : No output
  • Answer: b) 2 3 4 5

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

    #include < stdio.h >
    int main(){
       int j=2,k=5,m=6,n=9;
       while(j < k){
           while(m < n)
           {
            printf("Hello");
            m++;
            }
         j++;
    }
    return 0;
    }
        

  • Options
  • a : Hello Hello Hello
    Hello Hello Hello
  • b : Hello Hello Hello
  • c : Hello
  • d : No output
  • Answer: b) Hello Hello Hello

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

    #include < stdio.h >
    int main(){
      int number=4;
      while(number!=8)
      {
      printf("\n%d",2*number);
      number=number+2;
      }
    return 0;
    }
    

  • Options
  • a : 8 12 16
  • b : 8 12
  • c : 8 12 14
  • d : 8
  • Answer: b) 8 12

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

    #include 
    int main()
    {        
      int data=5,counter;
      for(counter=1;counter<=5;counter++)
          data+=counter;
          printf("%d",data);
          return 0;
    }
    

  • Options
  • a : 11
  • b : 15
  • c : 12
  • d : 20
  • Answer: d) 20

    TCS