On the difference between return and exit in C language _c language

Source: Internet
Author: User
Tags exit in function prototype

1. Exit is used to end the program at any time while the program is running, and exit parameters are returned to the OS. The Exit function is also implicitly called at the end of the main function. The Exit Function first executes the function that is enlisted by the atexit () function, and then does some of its own cleanup, refreshes all output streams, closes all open streams, and closes temporary files created by the standard I/O function tmpfile (). Exit is the end of a process that deletes the memory space used by the process while returning the error message to the parent process, and return returns the function value and exits the function.

2. Return is a language-level, which represents the call stack returns, and exit is the system call level, which represents the end of a process.

The 3.exit function exits the application and returns a state of the application to the OS, which identifies some running information for the application. and the machine and the operating system is generally 0 for normal exit not 0 for abnormal exit

function prototype void exit (int status); (header file stdlib.h)

4. Return is returned function call, if return is the main function, then exit the program
Exit is to force the program to quit at the call, and the program ends at once.

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.