我正在尝试使用以下程序创建堆栈溢出运行时异常:
void f(int a) {
cout << a << ", ";
f(++a);
}
int main () {
f(0);
return 0;
}
当我运行这个程序时,我的计算机运行大约 261824call stack
然后command terminated
发生运行时错误。现在我想知道:
- 这是堆栈溢出的一个很好的例子吗?如果是,为什么
command terminated
会发生错误? - 我怎么能
try
,catch
堆栈溢出异常? - 我有很多空闲内存;为什么我的堆栈没有使用我所有的内存?
- 我怎样才能确定堆栈的大小对应于我的
call stack
?