【发布时间】:2023-04-03 09:29:01
【问题描述】:
这是我的代码
运行时内存将取决于操作系统,但我不想要那个级别。只想从基础级别解决这类问题。
include <studio.h>
int calculate(int n);
int number = 8;
int main(){
int add;
add = calculate(number);
return 0;
}
int calculate(int x){
if(x==0){
return x;
}else{
return x+calculate(x-1);
}
}
【问题讨论】:
-
使用
#include <stdio.h>而不是include <studio.h> -
'运行时内存将取决于操作系统',没错。您的小程序 ios 如此简单,以至于代码、数据、堆栈等段将成为操作系统加载程序和虚拟内存管理器提供的初始工作集。通过检查链接器映射文件,您可以了解您的程序需要多少内存。
标签: c++ c stack memory-layout