Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between exit and return in C language

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "what is the difference between exit and return in c language". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the difference between exit and return in c language".

1. The return that returns the value of the function is the keyword, and exit is a function.

Return is language-level, which represents the return of the call stack; exit is system call-level, which represents the end of a procedure.

2. Return is the exit of the function, and exit is the exit of the process.

3. Return is provided by C language, and exit is provided by operating system (or function library).

Example # include / * ISO C * / void exit (int status); void _ Exit (int status); # include / * POSIX * / void _ exit (int status)

Expansion of knowledge points:

The difference between return and exit in C language

1 exit exit is used to end the program at any time while the program is running, and the parameter exit is returned to the program. The exit function is also implicitly called at the end of the main function. When the exit function runs, it first executes the function registered by the atexit () function, and then does some of its own cleanup, refreshing all output streams, closing all open streams, and closing temporary files created by the standard Imax O function tmpfile (). Exit terminates a process, which deletes the memory space used by the process and returns the error message to the parent process, while return returns the value of the function and exits the function

2 exit return is at the language level, which represents the return of the call stack, while exit is at the system call level, which indicates the end of a process.

The 3Jing exit function exits the application and returns a status of the application to OS, which identifies some running information of the application.

4, related to the machine and operating system, generally 0 is normal exit, non-0 is abnormal exit

5Jing void exit (int status)

6The argument to the 6Magneatexit () function is a function pointer, which points to a function that has no arguments and no return value. The function prototype of atexit () is: int atexit (void (*) (void)); you can register up to 32 handlers with atexit () in a program, and these handlers are called in the opposite order to the order in which they are registered, that is, the first and the last.

The above is all the content of this article entitled "what's the difference between exit and return in c language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report