Exit () and _ exit () and return, exit_exitreturn

Source: Internet
Author: User

Exit () and _ exit () and return, exit_exitreturn
The difference between exit () and return: According to ansi c, return and exit () are used in the originally called main () with the same effect. However, note that "initial call" is used here ". If main () is in a recursive program, exit () will still terminate the program; but return will hand over control to the first level of recursion until the first level, at this time, return will terminate the program. Another difference between return and exit () is that it terminates the program even if exit () is called in a function other than main. _ Exit () differs from exit: header file: exit: # include <stdlib. h> _ exit: # include <unistd. h> _ exit () function: directly stop the process, clear its memory space, and destroy various data structures in the kernel. exit () the functions are encapsulated based on these and several processes are added before execution and exit. The biggest difference between the exit () function and the _ exit () function is that the exit () function checks the file opening before calling the exit system, and writes the content in the File Buffer back to the file.
What is the difference between return and exit (0 )?

Let's take a look at the definitions of these two statements in the book. Return is used to return a function. It is a basic statement. Exit (0) is a function with a parameter, which indicates that the program has ended. The reason why you cannot find their differences is that the two statements have the same surface effect in the main function, and they all terminate the program (but in essence they are different ). Also, if you add these two statements to other functions (when the function is running, it will not end the Program), they are different. I was more impressed when I tested it myself. Typing on a cell phone only. I hope it will help you.
From UC Browser
What is the difference between exit (0) and exit (1) in C language ??

Exit seems to be in stdio. h, so it must contain header files.
Return indicates a function call. If the main function is returned, the system exits the program.
Exit is to forcibly exit the program at the call. Once the program is run, it will end.
-------------------------------------------------------------------
Return

Yes

Function return
While exit indicates exit.
-------------------------------------------------------------------
Exit (1) indicates abnormal exit. This 1 is returned to the operating system, but DOS does not seem to require this return value.
Exit (0) indicates normal exit
-------------------------------------------------------------------
No matter where it is written, it is a program launched, dos and windows are nothing different, at most the system processing is different.
Numbers 0, 1 and-1 are written to the environment variable ERRORLEVEL. Other programs can determine the end state of the program.
Generally, 0 is normal, and other numbers are abnormal. You can specify the corresponding error.
-------------------------------------------------------------------
If it is returned to the operating system, 0 indicates normal exit, and other values indicate abnormal exit. Before exiting, You can provide some prompt information or check the cause of the error in the debugging program.
Reference: topic.csdn.net/t/20030412/00/1650539.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.