prev up next   top/contents search

comp.lang.c FAQ list · Question 20.16

Q: Which is more efficient, a switch statement or an if/else chain?


A: 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).

See also questions 20.17 and 20.18.


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North