c-cpp/学习笔记之IKM C++ 11 at main · haoran119/c-cpp (github.com)
- Q1. If most of the calls to function foo() below pass one of 10 particular values, which method will significantly reduce the execution time of calling the function?
- A. Replace * with an if-else block testing for the 10 values, assigning r accordingly
- B. Remove inline
- C. Delete foo() and move the time-consuming operation to its caller
- D. Replace * with code performing a table lookup, with the 10 values and corresponding values of r
- E. Replace * with swtich
- A1. D ?
1 inline int foo (int x) { 2 int r; 3 4 * // time-consuming operation on x, result stored in r 5 6 return r; 7 }