[Solved] Program doesn’t stop after returning 0 from main


Or is the problem in the rest of the code?

Possibly. Perhaps you’ve corrupted your stack somehow, so that you’re “returning” from main to someplace you didn’t expect. We can’t really know without an complete, verifiable example.

How can I make it finish after returning 0?

You can use the kill command on MacOS to terminate it forcefully. Using the GUI task manager may or may not work.

But perhaps a more effective course of action would be to attach a debugger to the process and see what it’s actually doing.

You could read this explanation on how to do this on MacOS with XCode – but I don’t use MacOS, so I wouldn’t know. Also, @SergeyA graciously suggests trying using pstack to get the process’ current stack. Of course, if the stack has been garbled, there’s no telling what you’ll actually get.

Make sure the application is compiled with debugging information included.

Finally – it’s probably better to run the program with a debugger attached in the first place, and set a breakpoint at the last cout << line.

2

solved Program doesn’t stop after returning 0 from main