side effect

http://www.learncpp.com/cpp-tutorial/33-incrementdecrement-operators-and-side-effects/

A side effect is a result of an operator, expression, statement, or function that persists even after the operator, expression, statement, or function has finished being evaluated.

Side effects can also be dangerous:

1
2
int x = 5;
int nValue = Add(x, ++x);

C++ does not define the order in which function parameters are evaluated. If the left parameter is evaluated first, this becomes a call to Add(5, 6), which equals 11. If the right parameter is evaluated first, this becomes a call to Add(6, 6), which equals 12!


Note that side effects are not confined to operators, expressions, and statements. Functions can also have side effects

發佈了7 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章