Martin York brought out the fact that departure doesn't carry out the essential cleanup as return does.
Use return instead of exit whenever possible.
If you don't already have yourself in main and you want to leave the programme elsewhere, go back there first.
Think on the illustration below.
A file with the specified content will be produced by the ensuing software.
However, the compiler cannot guarantee that the file will contain the needed content if return is commented and exit(0) is
uncommented.
int main()
{
ofstream os("out.txt");
os << "Hello, Can you see me!\n";
return(0);
//exit(0);
}
Additionally, having several exit points in a programme will make debugging more difficult.
Use the exit only when it makes sense.