Basic and Advance C Question:
Download Job Interview Questions and Answers PDF
Which is more efficient, a switch statement or an if else chain?
Answer:
The differences, if any, are likely to be slight. The switch statement was designed to be efficiently implementable, though the compiler may choose to use the equivalent of an if/else chain (as opposed to a compact jump table) if the case labels are sparsely distributed.
Do use switch when you can: it's certainly cleaner, and perhaps more efficient (and certainly should never be any less efficient).
Do use switch when you can: it's certainly cleaner, and perhaps more efficient (and certainly should never be any less efficient).
Download C Programming Interview Questions And Answers
PDF
Previous Question | Next Question |
Is there a way to switch on strings? | How can I swap two values without using a temporary? |