CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
When is a switch statement better than multiple if statements?



Category C Interview Questions
Rating (3.0) By 1 users
Added on 7/19/2006
Views 1833
Rate it!
Answers:

The switch statement is better than multiple if statements when there are more than two alternatives to be selected whether the case value matches to the variable of either character or integer type.



IN CASE OF A SWITCH STATEMENT,
THE CURSOR STRAIGHT AWAY JUMPS TO THE REQUIRED CASE AND OVERLOOKS OTHER STATEMENTS. AS SOON AS THE EXECUTION IS OVER IT MOVES OUT OF THE OTHER IRREVALENT STEPS PERTAINING TO THE REQUIRED CONDITION
BY THE HELP OF "break" STATEMENT,THEREBY REDUCING THE TIME COMPLEXITY OF THE PROGRAM.
WHEREAS "if" STAEMENT IS USEFUL WHEN THE NUMBER OF CONDITIONS TO BE CHECKED IS LESS.



 Posted by: ANIRUDDHA SANYAL    

Contact ANIRUDDHA SANYAL  Contact ANIRUDDHA SANYAL

In menu-driven programs.



 Posted by: ranu    

Contact ranu  Contact ranu


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
Can static variables be declared in a header file?


View Answer
Difference between Funtion to pointer and pointer to function

View Answer
What is #line used for?


View Answer
Can a variable be both const and volatile?


View Answer
All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
?? Programs run under DOS environment,
?? The underlying machine is an x86 system,
?? Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).

Predict the output or error(s) for the following:

i) void main()
{
int const * p=5;
printf("%d",++(*p));
}


View Answer
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}


View Answer
vi) main()
{
extern int i;
i=20;
printf("%d",i);
}


View Answer
vii)7. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}


View Answer
viii) main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}


View Answer
main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}


View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6055/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.64