std::cout 參數的求值順序
傳遞給std::cout 的參數的求值順序可能會令人困惑,尤其是當一個或多個參數是修改另一個參數值的函數呼叫時。
程式碼範例
考慮以下C 程式碼片段:
#include <iostream> bool foo(double &m) { m = 1.0; return true; } int main() { double test = 0.0; std::cout << "Value of test is : \t" << test << "\tReturn value of function is : " << foo(test) << "\tValue of test : " << test << std::endl; return 0; }
意外輸出
意外輸出Value of test is : 1 Return value of function is : 1 Value of test : 0
意外輸出
意外輸出
意外輸出
意外輸出
std::cout << "Value of test before function call: " << test << std::endl; foo(test); std::cout << "Value of test after function call: " << test << std::endl;
Value of test before function call: 0 Value of test after function call: 1
以上是參數求值順序如何影響 C 中的「std::cout」輸出?的詳細內容。更多資訊請關注PHP中文網其他相關文章!