Last Updated :
10 Apr, 2024
What will be the output of the following C++ program segment?
#include <iostream>
using namespace std;
int main()
{
char inchar = \'A\';
switch (inchar)
{
case \'A\' :
cout << \"choice A \\n\" ;
case \'B\' :
cout << \"choice B \";
case \'C\' :
case \'D\' :
case \'E\' :
default:
cout << \"No Choice\" ;
return 0;
}
}
(A) No choice
(B) Choice A
(C) Choice A
Choice B No choice
(D) Program gives no output as it is erroneous
Answer: (C)
Explanation: There is no break statement in case ‘A’. If a case is executed and it doesn’t contain break, then all the subsequent cases are executed until a break statement is found. That is why everything inside the switch is printed.
Share your thoughts in the comments
Please Login to comment...