The difference between Exit function exits () and return function returns () in program code
- Exit (0): run The program normally and exit the program;
- Exit (1): Abnormal operation results in exiting the program;
- Return (): Returns a function that, if in the main function, exits the function and returns a value.
Analytical:
1. Return returns the function value, which is the keyword; exit is a function.
2. Return is a language level that represents the return of the call stack, and exit is the system call level, which represents the end of a process.
3. Return is the exit of the function (return); Exit is the exit of the process.
4. return is provided by the C language, and exit is provided by the operating system (or given in the function library). Exit is a library function, exit (1) indicates that the program exits when an error occurs, and exit (0) indicates a graceful exit. In Stdlib.h, the Exit function is defined in this way: void exit (int status). This system call is used to terminate a process, regardless of where in the program, as long as the exit is executed, the process will run from the end of the process. Referring to exit this system call, it is necessary to mention another system call, _exit,_exit () function is located in Unistd.h, compared to exit (), the function of the _exit () is the simplest, directly terminates the process of running, releasing its memory space used, and destroys the data structure in memory, and exit () is to check the state of the file before the process exits, and write the contents of the file buffer back to the file.
5. Return is used to end the execution of a function, to pass the execution information of the function to other calling functions; the exit function exits the application, deletes the memory space used by the process, and returns a state of the application to the OS or its parent process, which identifies some of the application's operational information. This information is related to the machine and the operating system, usually 0 for normal exit, not 0 for abnormal exit.
6. Calling return and exit in a non-main function is obvious, but the phenomenon of calling return and exit in the main function is blurred, and in most cases the phenomenon is consistent.
Reference: http://blog.sina.com.cn/s/blog_99f5031a0101lshp.html
The difference between Exit function exits () and return function returns () in program code