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
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 |
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 |
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 |
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 |
How will you delete a node in DLL?
how many errors in c explain deply
main() { char x; while(x=0;x<=255;x++) printf("\nAscii value %d Charater %c",x,x); }
How can I automatically locate a programs configuration files in the same directory as the executable?
What does the c in ctime mean?
How can I increase the allowable number of simultaneously open files?
What is sparse file?
what is the difference between exit() and _exit() functions?
How can you increase the allowable number of simultaneously open files?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What are pointers in C? Give an example where to illustrate their significance.
int *p=20; if u print like dis printf("%d",p); o\p:- 20; how is it possible? plz give me the explanation.