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 |
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
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)
can we write a c program with out using main
What is structure in c language?
Why is c platform dependent?
Do pointers need to be initialized?
Why c is called free form language?
Why the use of alloca() is discouraged?
Is this program statement valid? INT = 10.50;
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
What is a scope resolution operator in c?
write a c program to find largest of three numbers using simple if only for one time.