what is the different between if-else and switch statment
(other than syntax)
Answer Posted / sujith
I would like to answer this question from a compiler
perspective. When we have if else or if else tree, we have
many compare instructions ( assembly generated by compiler)
where as switch has only one compare and jump instruction.
If the idea is to does something after comparing the values,
it is always better to go with the switch case than if else
tree.
I would appreciate analyzing the assembly code, with the
same source, with if else tree and switch case statements.
| Is This Answer Correct ? | 58 Yes | 33 No |
Post New Answer View All Answers
Explain the difference between #include "..." And #include <...> In c?
Not all reserved words are written in lowercase. TRUE or FALSE?
Can two or more operators such as and be combined in a single line of program code?
If null and 0 are equivalent as null pointer constants, which should I use?
Is register a keyword in c?
What is an identifier?
Explain the advantages and disadvantages of macros.
Should a function contain a return statement if it does not return a value?
a c code by using memory allocation for add ,multiply of sprase matrixes
How is actual parameter different from the formal parameter?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What is the purpose of sprintf() function?
How do I use void main?
What are terms in math?
What is a constant and types of constants in c?