Paper Tayyari

Lecture 8: Switch Statement

MCQs, short and long questions from lecture 8.Lecture 8 ki MCQs, short aur long sawal.

4 MCQs · 4 MCQs from past papers4 MCQs · 4 MCQs past papers se

Start mock testMock test shuru karein
DoneHal kiye 0/4
– correctsahi
1.
★ Final term 2017 (paper 2)

When break statement is encountered in switch statement, it ______

  1. AStops the entire program
  2. BStops the execution of current statement
  3. CExits from switch statement
  4. DRepeats the switch statement

break transfers control to the statement after the switch block.

2.
★ Solved MCQs collection

If the break statement is missed in switch statement then,

  1. AThe compiler will give error
  2. BThis may cause a logical error
  3. CNo effect on program
  4. DProgram stops its execution

Without break, control falls through into the next case, which can cause a logical error.

3.
★ Past paper collection

What is the output of the following code, if the first case is true switch (var) { case 'a':cout<<"apple"<<endl; case 'b':cout<<"banana"<<endl; case 'm':cout<<"mango"<<endl; default: cout<<"any fruit"<<endl; }

  1. Aapple
  2. Bapple any fruit
  3. Capple banana mango any fruit
  4. Dnone of above

Without break, all statements from case 'a' onward run.

4.
★ Past paper collection

_________statement is used to terminate the processing of a particular case and exit from switch structure.

  1. Aif
  2. Bgoto
  3. Cbreak
  4. Dcontinue

break ends the current case and leaves the switch.