a If the following switch statement were implemented using a
(a) If the following switch statement were implemented using a jump table, how many elements
would the table contain? Would it make sense to use a jump table to implement this switch
statement? Why or why not? If not then what type of implementation will be more suitable?
Why?
switch (i) {
case 40: j = a; break;
case 41: j = b; break;
case 42: j = c; break;
case 43: j = d; break;
case 44: j = e; break;
case 45: j = r; break;
case 46: j = g; break;
}
(b) Answer the same questions as in part (a), using the following switch statement instead:
switch (i) {
case 20: j = a; break;
case 67: j = b; break;
case 97: j = c; break;
case 400: j = d; break;
case 310: j = e; break;
case 10: j = f; break;
}
Solution
Answer:
In part a. 7 elements would contain in a table. And it makes sense to make jump table for switch statement because it tells how many times a code can jump to the other area of code.
In part b , 6 elments would contain in a table. It makes sense to make jump table for switch statement because i tells us how many times a code can jump to the other area fo code.

