Introduction to exit() function

1.exit() function introduction

Function name: where exit()
is located Header file: stdlib.h
Function: Close all files and terminate the executing process.
Usage format: void exit(int status)

exit() is a computer function.
exit() is usually used in a subroutine to terminate the program. After use, the program ends automatically and jumps back to the operating system.

exit(0) indicates that the program exits normally.
exit⑴/exit(-1) indicates that the program exits abnormally.

exit() ends the current process/current program/in the entire program, as long as exit is called, it ends.
exit(x) (x is not 0) means abnormal exit, and this x is returned to the operating system (including UNIX, Linux, and MS DOS) for use by other programs.

2. The difference between return and exit()

2.1
Using return and exit() in the originally called main() has the same effect.
2.2
If main() is in a recursive program, exit() will still terminate the program; but return will
transfer control to the previous level of recursion until the first level, at which point return will terminate the program. Another difference between return and exit()
is that even if exit() is called in a function other than main(), it will terminate the program.

Guess you like

Origin blog.csdn.net/weixin_42581177/article/details/127575264