Machine-translated by Google. Questions are authored in English.
Top

Discussion

A case or switch statement with many labels is commonly translated into

  • A.a sequence of nested while loops testing each label
  • B.a procedure call for each of the case alternatives
  • C.a jump table indexed by the case value
  • D.a single conditional jump with several destinations

Answer: C

A dense range of values makes a table lookup the cheapest option. Sparse or wide ranges are better served by a chain of comparisons or a binary search over the values. The choice is made by measuring how densely the labels are packed.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.