Suppose you are required to write a C/C++ program for a bank in which all transactions of a day will be compared. Keep in mind a huge volume of transactions per day:
Your code should have following features:
- The processing speed must be high.
- The logic of the program must be simple.
Which decision structure (if-else and switch statement) would you choose to achieve above mentioned features of code, and also mention reasons in favor of your choice.
[Note: Answer must be comprehensive with logical reasoning. Confine your answer within 3 to 5 lines]
In my opinion, switch statements id better than If-Else. Switch statements have its best uses then there are more environments. As we know that if statements checks for all the conditions and then when the condition is matched then the following body inside it is executed but this is not the case with switch condition as it directly checks for the compatible conditions and executes the code.
The reason behind the selection of switch statement is;
Working speed of switch statement is much faster than if-else.
The reason is that compiler produces a jump table for a switch in the course of assembling. Thus, during accomplishment, as a substitute of testing which case is contented, it only picks which case has to be accomplished.
It is more understandable and in parallel to if-else testimonials.
Switch statement is more manageable for taking higher level of transactions than if-else