If I run this program repeatedly, why the last number printed before seg-fault varies?

Viewed 107

The question is about how linux handle the stack. Why is not deterministic when I get segmentation-fault running this code?

#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>

void step(int n) {
    printf("#%d\n", n);
    step(n + 1);
}

int main() {
    step(1);
    return 0;
}
2 Answers
Related