IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Control Instructions - Discussion

@ : Home > C Programming > Control Instructions > Point Out Errors - Discussion

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;
}

[A]. There is no break statement in each case.
[B]. Expression as in case 3 + 2 is not allowed.
[C]. Duplicate case case 5:
[D]. No error will be reported.

Answer: Option A

Explanation:

Because, case 3 + 2: and case 5: have the same constant value 5.


Prudhvi said: (Mon, Jul 11, 2011 02:32:35 PM)    
 
Please explain in detail.

Abhishek said: (Wed, Jul 20, 2011 08:20:18 PM)    
 
Is variable addition is allowed in case statements ?

Raj said: (Thu, Sep 22, 2011 05:30:07 PM)    
 
Because case 3+2 is equal to case 5. So ambiguity occurs.

Hyma said: (Wed, May 16, 2012 10:08:27 AM)    
 
Yes addition is allowed in case statements but case 3+2 is equal to case 5 so ambiguity is occurs.

Knight said: (Sat, May 19, 2012 11:37:52 AM)    
 
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.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!