C Programming - Control Instructions - Discussion


Point out the error, if any in the program.

int main()
    int a = 10;
    printf("This is c program.");
	return 0;

[A]. Error: No case statement specified
[B]. Error: No default specified
[C]. No Error
[D]. Error: infinite loop occurs

Answer: Option C


There can exists a switch statement, which has no case.

Nancy Silviya A K said: (Jul 26, 2010)  
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

Yasmeen Mahmoud said: (Sep 4, 2011)  
I need to understand what will happen inside { } of switch


Aslamkhan said: (Oct 13, 2011)  
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: (Oct 27, 2011)  
Basically switch statement structure is like below

int =5; / here the variable must be intialized/
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.

Vicky said: (Mar 15, 2016)  
Why not infinite loop as the switch condition is always true?

Vishu said: (Jan 16, 2017)  

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

I hope you understand.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.