Exit (0) and exit (1)

Source: Internet
Author: User

Exit seems to be in the "stdlib. H" header file, so it must contain the header file
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.

Exit (1) indicates an abnormal exit. This 1 is returned to the Operating System
Exit (0) indicates normal exit

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.

1 # include "iostream. H"
2 # include "stdlib. H"
3 void fun ()
4 {
5 int * P;
6 if (P = new INT) // If P is assigned to the space, continue to execute (very rogue writing)
7 {
8 * P = 5;
9 cout <* P <Endl;
10 Delete P;
11}
12 else
13 {
14 cout <"heap error" <Endl;
15}
16}
17 void main ()
18 {
19 fun ();
20 int * pA;
21 pA = new int [5];
22 if (! Pa) // if no space is allocated, call exit (1) to exit the program.
23 {
24 cout <"heap error" <Endl;
25 exit (1 );
26}
27 For (INT I = 0; I <5; I ++)
28 pa [I] = I + 1;
29 for (I = 0; I <5; I ++)
30 cout <pa [I] <"";
31 cout <Endl;
32 Delete [] Pa;
33}

From http://hi.baidu.com/zs1002229/blog/item/45ec5a4cd7de06c0d0c86ad1.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.