C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Point Out Errors (Q.No. 5)
5.
Which of the following errors would be reported by the compiler on compiling the program given below?
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("First");
case 2:
printf("Second");
case 3 + 2:
printf("Third");
case 5:
printf("Final");
break;
}
return 0;
}
Answer: Option
Explanation:
Because, case 3 + 2: and case 5: have the same constant value 5.
Discussion:
18 comments Page 2 of 2.
Ravi said:
6 years ago
Arithmetic operation is allowed in switch case or not?
i.e case (arithmetic operation).
i.e case (arithmetic operation).
Ranjith karthick said:
1 decade ago
I have an doubt in switch usage of operator is allowed or not. Can any one explain?
Pradeep said:
3 years ago
In the switch case, no duplicate case will be allowed.
Am I right?
Am I right?
RAJ said:
1 decade ago
Because case 3+2 is equal to case 5. So ambiguity occurs.
Dhruv said:
10 years ago
What will case 3/2: be evaluated as? Can anyone help?
Abhishek said:
1 decade ago
Is variable addition is allowed in case statements ?
Prudhvi said:
1 decade ago
Please explain in detail.
Vishalakshi said:
9 years ago
Thank you @Amrita.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers