C++中一个由编译器决定结果的程序

来源:互联网 发布:nginx检查配置文件 编辑:程序博客网 时间:2024/06/08 14:46

【代码】

#include <iostream>using namespace std;int get(int i){cout << i << endl;return i + 1;}int Cal(int a, int b) {return a + b;}int main() {cout << Cal(get(0), get(10)) << endl;return 0;}

程序输出多少?答案是视编译器而定,可能是0 10 12,也可能是 10 0 12。这是因为函数参数的执行顺序是 Unspecified Behavior。vs2013的编译器的执行结果为10 0 12

0 0
原创粉丝点击