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

An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

0 Answers  


GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)

0 Answers  


can we write a c program with out using main

3 Answers  


What is structure in c language?

0 Answers  


Why is c platform dependent?

0 Answers  






Do pointers need to be initialized?

0 Answers  


Why c is called free form language?

0 Answers  


Why the use of alloca() is discouraged?

2 Answers   Oracle,


Is this program statement valid? INT = 10.50;

0 Answers  


Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV

5 Answers   Accenture,


What is a scope resolution operator in c?

0 Answers  


write a c program to find largest of three numbers using simple if only for one time.

1 Answers  


Categories