You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Call the [exit](../c-runtime-library/reference/exit-exit-exit.md) function.
14
-
- Call the [abort](../c-runtime-library/reference/abort.md) function.
15
-
- Execute a [return](return-statement-cpp.md) statement from `main`.
11
+
- Call the [`exit`](../c-runtime-library/reference/exit-exit-exit.md) function.
12
+
- Call the [`abort`](../c-runtime-library/reference/abort.md) function.
13
+
- Execute a [`return`](return-statement-cpp.md) statement from `main`.
16
14
17
-
## exit function
15
+
## `exit` function
18
16
19
-
The [exit](../c-runtime-library/reference/exit-exit-exit.md) function, declared in \<stdlib.h>, terminates a C++ program. The value supplied as an argument to `exit` is returned to the operating system as the program's return code or exit code. By convention, a return code of zero means that the program completed successfully. You can use the constants EXIT_FAILURE and EXIT_SUCCESS, also defined in \<stdlib.h>, to indicate success or failure of your program.
17
+
The [`exit`](../c-runtime-library/reference/exit-exit-exit.md) function, declared in \<stdlib.h>, terminates a C++ program. The value supplied as an argument to `exit` is returned to the operating system as the program's return code or exit code. By convention, a return code of zero means that the program completed successfully. You can use the constants `EXIT_FAILURE` and `EXIT_SUCCESS`, also defined in \<stdlib.h>, to indicate success or failure of your program.
20
18
21
19
Issuing a **`return`** statement from the `main` function is equivalent to calling the `exit` function with the return value as its argument.
22
20
23
-
## abort function
21
+
## `abort` function
24
22
25
-
The [abort](../c-runtime-library/reference/abort.md) function, also declared in the standard include file \<stdlib.h>, terminates a C++ program. The difference between `exit` and `abort` is that `exit` allows the C++ run-time termination processing to take place (global object destructors will be called), whereas`abort` terminates the program immediately. The `abort` function bypasses the normal destruction process for initialized global static objects. It also bypasses any special processing that was specified using the [atexit](../c-runtime-library/reference/atexit.md) function.
23
+
The [`abort`](../c-runtime-library/reference/abort.md) function, also declared in the standard include file \<stdlib.h>, terminates a C++ program. The difference between `exit` and `abort` is that `exit` allows the C++ run-time termination processing to take place (global object destructors get called), but`abort` terminates the program immediately. The `abort` function bypasses the normal destruction process for initialized global static objects. It also bypasses any special processing that was specified using the [`atexit`](../c-runtime-library/reference/atexit.md) function.
26
24
27
-
## atexit function
25
+
## `atexit` function
28
26
29
-
Use the [atexit](../c-runtime-library/reference/atexit.md) function to specify actions that execute prior to program termination. No global static objects initialized prior to the call to **atexit** are destroyed prior to execution of the exit-processing function.
27
+
Use the [`atexit`](../c-runtime-library/reference/atexit.md) function to specify actions that execute before the program terminates. No global static objects initialized before the call to `atexit` are destroyed before execution of the exit-processing function.
30
28
31
-
## return statement in main
29
+
## `return` statement in `main`
32
30
33
-
Issuing a [return](return-statement-cpp.md) statement from `main` is functionally equivalent to calling the `exit` function. Consider the following example:
31
+
Issuing a [`return`](return-statement-cpp.md) statement from `main` is functionally equivalent to calling the `exit` function. Consider the following example:
34
32
35
33
```cpp
36
34
// return_statement.cpp
@@ -42,7 +40,7 @@ int main()
42
40
}
43
41
```
44
42
45
-
The `exit` and **`return`** statements in the preceding example are functionally identical. However, C++ requires that functions that have return types other than **`void`** return a value. The **`return`** statementallows you to return a value from `main`.
43
+
The `exit` and **`return`** statements in the preceding example are functionally identical. Normally, C++ requires that functions that have return types other than **`void`** return a value. The `main` function is an exception; it can end without a **`return`** statement. In that case, it returns an implementation-specific value to the invoking process. The **`return`** statement allows you to specify a return value from `main`.
46
44
47
45
## Destruction of static objects
48
46
@@ -92,7 +90,7 @@ Another way to write this code is to declare the `ShowData` objects with block s
92
90
93
91
```cpp
94
92
int main() {
95
-
ShowData sd1, sd2( "hello.dat" );
93
+
ShowData sd1( "CON" ), sd2( "hello.dat" );
96
94
97
95
sd1.Disp( "hello to default device\n" );
98
96
sd2.Disp( "hello to file hello.dat\n" );
@@ -101,4 +99,4 @@ int main() {
101
99
102
100
## See also
103
101
104
-
[main function and command-line arguments](main-function-command-line-args.md)
102
+
[`main` function and command-line arguments](main-function-command-line-args.md)
0 commit comments