I'm wondering how to get an stack overflow error with a simple example, such as:
int recursSum (int n)
{
return (n==1)? 1:n+recursSum(n-1);
}
I ask that stupid question because I only have some Segmentation fault, even with an empty function calling itself…
Am I missing something or is there any protection or something that prevents me for doing this?
A segmentation fault means that the memory protection kicked in and prevented you from accessing memory you did not have available. This can occur for a variety of reasons, but one reason indicated is stack overflow (overflowing the stack into some other segment of memory).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With