Differences between return and exit in C Language

Source: Internet
Author: User

1. Exit is used inProgramThe program is terminated at any time during the running process. The exit parameter is returned to the OS. The exit function is also called implicitly at the end of the main function. When the exit function is run, it will first execute the function registered by the atexit () function, and then perform some self-cleaning work, refresh all output streams, close all open streams, and close temporary files created using the standard I/O function tmpfile. Exit is to end a process. It will delete the memory space used by the process and return the error message to the parent process. Return is to return the function value and exit the function.

2. Return indicates the language level, which indicates the return of the call stack, and exit indicates the system call level, which indicates the end of a process.

3. The exit function exits the application and returns a state of the application to the OS. This State identifies some running information of the application. It is related to machines and operating systems. Generally, 0 indicates normal exit. If not, it indicates abnormal exit.

Function prototype void exit (INT status); (header file stdlib. h)

4. Return refers to the return function call. If the return is the main function, it is the exit program.
Exit is to forcibly exit the program at the call. Once the program is run, it will end.

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.