Contents    Prev    Next    Page+10   

How does use of table lookup compare to a switch statement?

  • A: Less source code to write
  • B: Runs faster
  • C: Uses less memory
  • D: Better software engineering
  • E: All of the above

    Answer: E

    Comparison of switch and table lookup.

    We will see that B and C are true by experiment with a real compiler:

    Pros use table lookup when they can. It is also very useful in hardware, e.g. as an approximate answer for the divide and square root instructions.