C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Errors (Q.No. 2)
2.
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
    int a = 10;
    switch(a)
    {
    }
    printf("This is c program.");
	return 0;
}
Error: No case statement specified
Error: No default specified
No Error
Error: infinite loop occurs
Answer: Option
Explanation:
There can exists a switch statement, which has no case.
Discussion:
6 comments Page 1 of 1.

AslamKhan said:   1 decade ago
In above prgm,we dont have the case for 'a' and also we dont have default. i.e.,here we dont have any thing under switch. Hence it will do nothing.i.e., here the switch is simply ignored by the compiler.

The answer is "No Error".But it will print "This is c program" will be printed.

Sathuragiri said:   1 decade ago
Basically switch statement structure is like below

int =5; / here the variable must be intialized/
switch(i)
{
case 1:
.....
...... / here i =5 so 5 case should be builded
}

but here no codings( Case ) inside of switch. so compiler ignores the switch statement.

Nancy Silviya A K said:   2 decades ago
it is said in the explanation of the 5th question that "variable names cannot be used with case statements". Doesnt any error comes here about this issue. or it is
correct???

Vishu said:   9 years ago
@Vicky,

It is not while loop, it is a switch statement.

I hope you understand.

Yasmeen mahmoud said:   1 decade ago
I need to understand what will happen inside { } of switch

switch(a)
{
}

Vicky said:   9 years ago
Why not infinite loop as the switch condition is always true?

Post your comments here:

Your comments will be displayed after verification.