Chapter 4 expression

Left and right values:

When an object is used as the right value, with the value (content) of an object; when the object is used as a value of the left, with the identity of the object (location in memory)

 

The order of evaluation: four kinds specify the order of evaluation of operands of the operator: '&&', '||', ':?', ','.

1, when processing complex expressions: Forced expression combining relationship parentheses composite program logic requirements doubt

           : If you change the value of an operation object, do not use this operand expression in other places

2, bool value not to participate in arithmetic: Because bool value will first be promoted to an int then converted evaluated, and the results may not be consistent with the logic

3, take the operator must be an integer operand type

Dividing the two orientation supplier always 0 integer (truncating the decimal part)

4, declare a reference copy of the element values ​​can be avoided

5, when the comparison operation unless the comparison is a Boolean type, do not use Boolean literals true and false operands as

6, unless otherwise do not have to decreasing post-increment version.

7, the pointer array is converted to occur most cases, but as decltype, &, sizeof conversion does not occur and the like typeid

8, may be cast in the presence of void type pointer removed

9, const_cast constant change properties of the object, but write of the result is undefined by const_cast constant (function commonly used in heavy-duty)

10, reinterpret_cast not the best.

11, try to avoid mandatory conversion, if it can not be avoided, it should try to limit the scope of the type conversion value, and record all relevant types of assumptions.

 

Guess you like

Origin www.cnblogs.com/xiaogaogao/p/11751156.html