In the following control structure which is faster?
1.Switch
2.If-else
and which consumes more memory?

Answers were Sorted based on User's Feedback



In the following control structure which is faster? 1.Switch 2.If-else and which consumes more me..

Answer / battini.laxman

switch is faster because when in nested if condition has to
check for each time. where as in switch it diectly check
only labels.

Is This Answer Correct ?    8 Yes 1 No

In the following control structure which is faster? 1.Switch 2.If-else and which consumes more me..

Answer / abhradeep chatterjee

According to me, switch is faster. cause in nested if-
else, the checking occurs in each step. So, more the
compiler checks, the more it takes time. So switch case is
faster.

Is This Answer Correct ?    1 Yes 0 No

In the following control structure which is faster? 1.Switch 2.If-else and which consumes more me..

Answer / vignesh1988i

as for as me is concerned switch is faster....

in if-else first it will check the if condition , if it is
true it's no problem.. but if it falls false, it will go
to the else part ...

but in switch case , the argument given inside switch
statement will see and automatically to the necessary case
of it... so by comaring the time constraint ,switch saves
the time for checking each else statement for every if....


thank u

Is This Answer Correct ?    1 Yes 1 No

In the following control structure which is faster? 1.Switch 2.If-else and which consumes more me..

Answer / deepak upadhyay

switch statement is more faster and consumes less memory
than if-else statement the reason being that the switch
statement is applied when we have a single variable to
check but in case of if-else different variable may be
checked at the same time.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

7. Identify the correct argument for the function call fflush() in ANSI C: A)stdout B)stdin C)stderr D)All the above

10 Answers   Accenture,


write a program for size of a data type without using sizeof() operator?

22 Answers   HCL, IBM,


What is printf () in c?

0 Answers  


#include<stdio.h> main(0 { printf("\n %d %d %d",sizeof(3),sizeof("3"),sizeof(3)); }

4 Answers   HCL,


What type of function is main ()?

0 Answers  






Write one statement equalent to the following two statements x=sqr(a); return(x); Choose from one of the alternatives a.return(sqr(a)); b.printf("sqr(a)"); c.return(a*a*a); d.printf("%d",sqr(a));

6 Answers   TCS,


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

0 Answers   TCS,


What is include directive in c?

0 Answers  


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

0 Answers  


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

0 Answers   HCL,


What are the advantages and disadvantages of pointers?

0 Answers  


Combinations of fibanocci prime series

0 Answers  


Categories