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
What does int main () mean?
Explain union.
what will be maximum number of comparisons when number of elements are given?
What is a dynamic array in c?
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.
What are global variables and explain how do you declare them?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What is the purpose of main() function?
what do you mean by enumeration constant?
What are the different types of linkage exist in c?
Why we not create function inside function.
What is a ternary operator in c?
what are the program that using a two dimensional array that list the odd numbers and even numbers separately in a given 10 inputs values
using only #include
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same