Why infinite recursion leads to seg fault

Every time you call f(), you increase the size of the stack – that’s where the return address is stored so the program knows where to go to when f() completes. As you never exit f(), the stack is going to increase by at least one return address each call. Once the stack segment is full up, you get a segfault error. You’ll get similar results in every OS.

Leave a Comment