C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Point Out Errors (Q.No. 7)
7.
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("Case1");
break;
case 1*2+4:
printf("Case2");
break;
}
return 0;
}
Answer: Option
Explanation:
Constant expression are accepted in switch
It prints "Case1"
Discussion:
5 comments Page 1 of 1.
Raman said:
7 years ago
There is no error if we initialise i=6 then case2 will be printed.
Nikhil said:
8 years ago
Why not case 1* 2+4: is an error?
Vikas said:
9 years ago
You are right @Anki.
Khush said:
1 decade ago
Why not case 1*2+4: is a error.
Anki said:
1 decade ago
Here i=1 switch terminate on case 1 and print "case1"after that break statment will run. So output is case1.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers