Switch case MCQ 13: Multiple parameters to switch case



Switch case MCQ 13: Multiple parameters to switch case


Problem Statement 13 : Multiple parameters to switch case

void main()
{
int choice = 1 ;
    switch(choice,choice+1,choice+2)
    {
       case var:
           printf("\nAllas");
           break;
       case 2:
           printf("\nBabo");
           break;
       case 3:
           printf("\nHurray");
           break;
    }
}

Options : Guess the Output

  1. Babo
  2. Error : Variables are not allowed
  3. Hurray
  4. Allas

Output :

 Hurray

Explanation

  1. Comma Returns Rightmost number
  2. Switch case contain 3 parameter
  3. Rightmost variable is ‘choice+2’ so it returns ‘choice+2’
  4. Value of choice = 1 So “Choice+2 = 3”
  5. Case 3 will be executed