void func(int depth){
if(depth== 0) return;
int number(12345);
cout << number; //it does something with number
func(--depth);
}
void func2(int depth){
if(depth== 0) return;
{
int number(12345);
cout << number; //it does something with number
}
func2(--depth);
}
void main(){
func(10); //will this function cost more memory?
func2(10);//will this function cost less memory?
}
Run Code Online (Sandbox Code Playgroud)
你好.我这里有两个功能.func2会花费更少的内存,因为它的数字(12345)被"{}"封装,所以当func2调用下一次迭代时,数字(12345)可以超出范围并消失吗?
我相信func会花费更多,因为它的数量(12345)即使到达下一次迭代时也不在范围之外?