//定义处可以给形参默认值,声明也可以给形参默认值 //不管何处给,形参默认值只能出现一次 //int sum(int a = 10, int b = 20); //形参带默认值的参数,只能从右向左给 //实际压栈也是从右向左 int sum(int a=10, int b=20) { return a+b; } int main(void) { int a = 10; int b = 20; int ret = sum(a,b); /* mov eax, dword ptr[ebp-8] push eax mov ecx, dword ptr[ebp-4] push ecx call sum */ cout<<"ret: "<<ret<<endl; ret = sum(a); /* push 14H mov ecx, dword ptr[ebp-4] push ecx call sum */ ret = sum(); //等同 sum(10,20); /* push 14H push 0Ah call sum */ }
总结: