InterviewSolution
| 1. |
If I Is An Integer Variable, Which Is Faster ++i Or I++? |
|
Answer» In ++i which is a pre-increment METHOD, there is only one instruction which is needed for INCREMENTING the variable for returning a new value. In the case of i++ which is a post-incremental method, there is a need for two instructions -one for saving the OLD compiler which is USED in the EXPRESSION and the other for the incrementation of the variable. In the post-incremental method, first the old value is returned and then the variable is incremented. This process is slower than the pre-incremental process. In ++i which is a pre-increment method, there is only one instruction which is needed for incrementing the variable for returning a new value. In the case of i++ which is a post-incremental method, there is a need for two instructions -one for saving the old compiler which is used in the expression and the other for the incrementation of the variable. In the post-incremental method, first the old value is returned and then the variable is incremented. This process is slower than the pre-incremental process. |
|