Discussion :: Control Instructions - Point Out Errors (Q.No.5)
|Prudhvi said: (Jul 11, 2011)|
|Please explain in detail.|
|Abhishek said: (Jul 20, 2011)|
|Is variable addition is allowed in case statements ?|
|Raj said: (Sep 22, 2011)|
|Because case 3+2 is equal to case 5. So ambiguity occurs.|
|Hyma said: (May 16, 2012)|
|Yes addition is allowed in case statements but case 3+2 is equal to case 5 so ambiguity is occurs.|
|Knight said: (May 19, 2012)|
|Addition, multiplication, division are allowed in case statement but both the operand should be constant, operation is performed at compile time, for this case compiler get confused while choosing case 5 (ambiguity). So it will raise compile time error.|
|Deepu said: (Nov 21, 2013)|
The cases cant be defined as the any operation methods!
Example: the following cases is not allowed.
etc aren't allowed.
The definition after the case must a mere number or the character upon what data type you define.
int a = 4;
or else it might be
|Naveen said: (Dec 25, 2013)|
you are wrong about those operation.
You can perform arithmetic operation on case expressions.
|Binal said: (Jan 4, 2015)|
|If there's no break statement used, case 5 will not matter right? So it should keep printing till break?|
|Sri said: (Mar 6, 2015)|
|I have a doubt for every case the break statement is needed or not. If it is not needed what will be the output? Can any one explain me?|
|Shree said: (Mar 15, 2015)|
|It is needed because the absence of break statement will leads the execution to continue
the codes until it finds break.
break;// if break statement is not included,then the output will 1 2. else the output will be 1.
|Ranjith Karthick said: (Aug 5, 2015)|
|I have an doubt in switch usage of operator is allowed or not. Can any one explain?|
|Dhruv said: (Oct 6, 2015)|
|What will case 3/2: be evaluated as? Can anyone help?|
|Mohit Bansal said: (Oct 16, 2015)|
printf("x=%d y=%d z=%d\n",x,y,z);
The output is x = 10, y = 10, z = 0.
|Venky said: (Oct 30, 2015)|
|I compiled it. And I got it error.
So the options are wrong. Also no duplicates should be present in switch.
|Amrita said: (Mar 8, 2016)|
I compiled it. Got the output as mentioned by you mohit.
y=x=10 means the values of x and y have been assigned as 10.
Z = x<10.
Means, value of z has been assigned as the same as x( here it is 10 from previous line).
But z is not <10. z is =10(since x is 10).
Thus the condition is false and so it returned a value 0. If the condition was true, then the compiler would return a value of 1 and the output would be x=10, y=10, z=1.
This is like a rule.
|Vishalakshi said: (Dec 14, 2016)|
|Thank you @Amrita.|
|Ravi said: (Jul 11, 2019)|
|Arithmetic operation is allowed in switch case or not?
i.e case (arithmetic operation).
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.