What is the difference between return and exit?

Source: Internet
Author: User
Exit () is a function that ends a process that deletes the memory space used by the process and returns the error message to the parent process, in which the wait system call will accept the return information.


Return returns the function value, which is the keyword.

We usually use return (0) in the main function, and return a value in such a way.


However, this is the form of void Main (), which is limited to non-void cases.

Exit () is usually used to terminate the program in a subroutine, and the program automatically ends the jumping operating system after use.


However, the value returned if main is defined as void is valid if the exit is used inside main, and exit does not need to consider the type, exit (1) is equivalent to return (1)

Exit (0); Normal exit
Non-0 is a non-normal exit
The number 0,1,-1 is written to the environment variable errorlevel, which can be used by other programs to determine the end state of the program.
General 0 for normal launch, the other number is abnormal, its corresponding error can be specified by itself.

What is the difference between return and exit?

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.