C please 53 What will be displayed by the following switch s
C++ please
53. What will be displayed by the following switch statement? char ch a switch (ch) case as case \'A\' cout ch endl; break; case \'b\' case \'B\' cout ch endl break case \'C\' case \'C\' cout ch endli break, case \'d case D\' cout ch endli A. abcd B. a D. ab 54. Does the following Switch statement cause a compile-time error? (n and alpha are of type int) switch (n) case 6 alpha 10; break case 2 case 5 alpha 20; break case 8 case 2 alpha- 30 A. Yes--one or more break statements are missing. B. Yes--there are duplicate case labels. C. Yes--the data types of the case labels are not valid. D. Yes--the default label is missing. E. No. 55. What is the output of the following C++code fragment? intl 120 Assume user types 30 cin in if intl 100) 66 (int2 50)) int3 int1 int2, else int3 intl int cout intl int int A. 20 30 150 B. 20 30 90 C. 2050 170 D. 2050 70 E. 20 30 70 56. Which of the following statements is syntactically correct? A. char c \'d\'; B. char c 00 C. char c \"d\" D, char c \"100\";Solution
53.
Answer:
B. a
Explanation:
The switch statement scans each case expression and enters that case to which it matches. Here since the switch expression contains ch as ‘a’, so it matches the first case and executes statements following it. And since this case expression contains break statement, it exits out of it after executing it.
54.
Answer:
B. Yes—there are duplicate case labels.
Explanation:
It is syntactically wrong to have duplicate case labels, so it would show compilation error.
55.
Answer:
B. 120 50 170
Explanation:
if( (int1 > 100) && (int2 = 50) )
In this line there are two logical expression joined by logical AND which would evaluate to true when both are true.
The expression “int1>100” evaluates to true since int1=120.
The expression “int2 = 50” is the trick in this expression. This expression is assignment expression instead of logical comparison expression. The logical comparison operator is “==” and not “=”. So the expression assigns 50 to int2 and all assignment operation evaluates to true. So this expression also evaluates to true.
So this line is executed:
int3 = int1 + int2;
since int2 is assigned 50, int3 = 120 + 50 = 170
56.
Answer:
Explanation:
All character variable should be initialized using single quotes and a single character.
57.
Answer:
Explanation:
Switch expressions are compact way of expressing the if-else statements. So every switch-case statements can be expressed in if-else statements. It’s the wish of the programmer to choose which to use.
58.
Answer:
Explanation:
Constant string cannot be concatenated using the ‘+’ operator, though string variables can be used for concatenation using ‘+’.
59.
Answer:
Explanation:
The find function of string returns the index of the character. Since ‘d’ is the 4th element in the string “Dandelion”, its returns as 3 for ‘d’ since it starts the index with 0.
60.
Answer:
Explanation:
The relational operator ‘<’ does lexicographical comparison of strings.
The strings “Mark” and “Mary” differ by their last letter ‘k’ and ‘y’.
The ASCII value of ‘k’ is less than ‘y’, so “Mark” is less than “Mary” and so it evaluates to true.

