Identify valid and invalid expressions from following switch statements: a. switch(1+2+23) b. switch(a+b+c) c. switch(1*2+3%4) d. switch(ab+cd)
Answers
Answered by
7
b.switch(a+b+c)is valid
others are invalid
others are invalid
samubhamare:
Can you specify the reason
Answered by
9
Answer: A and C are valid whereas B and D are valid under certain conditions.
The quantity value in switch case statements should be one among the following: integer or character or enumeration.
Thus, unless the variables in B and D are of the above types, the switch statement becomes invalid.
On the other hand, A and C quantity values are integers and thus, the switch statement is valid in these cases.
Similar questions