1, good at writing variable scope, the use of variables released in time
{
int a = 0;
A range of operations
}//When executed here, a in curly braces is released.
2, the former self-increase self-reduction is slightly higher than the self-reduction efficiency.
++i Efficiency > i++
-I. Efficiency > i--
3. if (conditional expression)
A, the conditional expression here can be calculated first, get a result, put into if () parentheses inside;
B, can also be placed directly inside ()
Recommendation: where appropriate, conditional expressions are placed directly inside the parentheses () because: (The circuit breaker of a logical operation expression ^_^)
Logical Expression,&& | | , sometimes the left-hand value can represent the value of the entire expression, and the expression on the right is no longer calculated, saving time.
4, can use 1 if to try not to use 2 if
Such as: can use
if () {}
else {}
Or
if () {}
else if () {}
else {} Try not to use
if () {}
if () {}
Because, 2 if is to judge 2 times, and if (else if) else structure only need to judge a condition satisfies, other condition not to judge.
Some tips for improving algorithmic efficiency