If Else in C++ MCQs Exercise I


Ques 1 If Else


What is the output of the following code if,a=7?


int main()
{
   int a;
   cin<<a; 
   if (++a*7<=49)
   {
	 cout<<"Hello";
   }
   else
   {
	 cout<<"Bye";	
   }
}

  a) Hello
  b) Bye
  c) Undefined
  d) Compilation Error


b is the correct option





Ques 2 If Else


What is the output of the following code?


int main() 
{
  int a = 6;
  if(a++==6)
    cout<<"Six"<<endl;
  else
    if(a==7)
       cout<<"Seven"<<endl;
  return 0;
}

  a) Runtime Error
  b) Compilation Error
  c) Seven
  d) Six


d is the correct option





Ques 3 If Else


What is the output of the following code?


int main()
{
   if(-1==-1)
   {
      cout<<"https://examprev.com";
   }
   else
   { 
     cout<<"https://smallcode.org";
   }
   return 0;
}

  a) https://examprev.com
  b) https://smallcode.org
  c) Compilation Error
  d) None of these


a is the correct option





Ques 4 If Else


What is the output of following C++ code?

    
int main()
{ 
   int a=90;

   if(a==15*6)
   {	
      if(a==90) break;
      cout<<"SmallCode";
   } 
   cout<<"Hello SmallCode"; 
}

  a) Compile error
  b) Hello SmallCode
  c) SmallCodeHello Smallcode
  d) SmallCode


a is the correct option





Ques 5 If Else


What is the output of following code?


int main()
{
int a = 1 ;
a = a - 1 ;

while(a)
{
    cout<<"its a while loop";
    a++ ;
}

return 0;
}

  a) 1
  b) 2
  c) 0
  d) infinite times


c is the correct option