die() stops the program and outputs the content
Exit stops the program from running without outputting content.
return is the return value
die stops when it encounters an error
Exit stops directly and does not run subsequent code. exit() can display the content.
return is a pure return value, but it will not run subsequent code.
exit(0): Run the program normally and exit the program;
exit(1): Abnormal operation causes the program to exit;
return(): Return function. If it is in the main function, it will exit the function and return a value.
In detail:
- return returns a function value and is a keyword; exit is a function.
- Return is at the language level, which represents the return of the call stack; exit is at the system call level, which represents the end of a process.
- return is the exit (return) of the function; exit is the exit of the process.
- return is provided by the C language, and exit is provided by the operating system (or given in the function library).
- return is used to end the execution of a function and transfer the execution information of the function to other calling functions; the exit function is to exit the application, delete the memory space used by the process, and return a status of the application to the OS. This status identifies some running information of the application. This information is related to the machine and operating system. Generally, 0 means a normal exit, and non-0 means an abnormal exit.
- The effect of calling return and exit in a non-main function is very obvious, but the phenomenon of calling return and exit in the main function is very vague. In most cases, the phenomenon is the same.