Skip to content

Commit 7de891e

Browse files
authored
Merge pull request #3326 from corob-msft/docs/corob/cpp-docs-2637
Docs/corob/cpp docs 2637
2 parents 46767da + d8477a9 commit 7de891e

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

docs/cpp/program-termination.md

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
---
22
title: "C++ program termination"
3-
description: "Describes the ways to exit a C++-language program."
4-
ms.date: "01/15/2020"
3+
description: "Learn about the standard ways to exit a C++-language program."
4+
ms.date: 12/07/2020
55
helpviewer_keywords: ["terminating execution", "quitting applications", "exiting applications", "programs [C++], terminating"]
6-
ms.assetid: fa0ba9de-b5f1-4e7b-aa65-e7932068b48c
7-
no-loc: [exit, abort, return, main, atexit, void]
86
---
97
# C++ program termination
108

119
In C++, you can exit a program in these ways:
1210

13-
- 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`.
1614

17-
## exit function
15+
## `exit` function
1816

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.
2018

2119
Issuing a **`return`** statement from the `main` function is equivalent to calling the `exit` function with the return value as its argument.
2220

23-
## abort function
21+
## `abort` function
2422

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.
2624

27-
## atexit function
25+
## `atexit` function
2826

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.
3028

31-
## return statement in main
29+
## `return` statement in `main`
3230

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:
3432

3533
```cpp
3634
// return_statement.cpp
@@ -42,7 +40,7 @@ int main()
4240
}
4341
```
4442

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`** statement allows 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`.
4644

4745
## Destruction of static objects
4846

@@ -92,7 +90,7 @@ Another way to write this code is to declare the `ShowData` objects with block s
9290
9391
```cpp
9492
int main() {
95-
ShowData sd1, sd2( "hello.dat" );
93+
ShowData sd1( "CON" ), sd2( "hello.dat" );
9694
9795
sd1.Disp( "hello to default device\n" );
9896
sd2.Disp( "hello to file hello.dat\n" );
@@ -101,4 +99,4 @@ int main() {
10199

102100
## See also
103101

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

Comments
 (0)