我有三个函数,funt1()
、funt2()
和 funt3()
。
int funt1()
{
cout<<"funt1 called"<<endl;
return 10;
}
int funt2()
{
cout<<"funt2 called"<<endl;
return 20;
}
void funt3(int x=funt1(), int y=funt2())
{
cout << x << y << endl;
}
我的主要
函数:
int main()
{
funt3();
return 0;
}
当我在 main()
方法中调用 funt3()
时,为什么先调用 funt1()
,然后 funt2()
?
最佳答案
这取决于您的编译器。其他人可能会先调用 funct2()
。 C 或 C++ 都不能保证函数参数的计算顺序。
参见 Parameter evaluation order before a function calling in C
关于c++ - 首先评估哪个默认参数,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7250150/