Skip to content

Commit d8b31f0

Browse files
authored
Merge pull request #4332 from AdrianWeaver/aweaver/cpp_void_4331
Add examples for void type in cpp (#4331)
2 parents 65934fa + ad70cb1 commit d8b31f0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/cpp/void-cpp.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: void (C++)"
33
title: "void (C++)"
4-
ms.date: 10/15/2021
4+
ms.date: 12/13/2022
55
f1_keywords: ["void_cpp"]
66
helpviewer_keywords: ["void keyword [C++]", "functions [C++], void", "pointers, void"]
77
ms.assetid: d203edba-38e6-4056-8b89-011437351057
@@ -16,16 +16,26 @@ In C++, a **`void`** pointer can point to a free function (a function that's not
1616

1717
You can't declare a variable of type **`void`**.
1818

19+
As a matter of style, the C++ Core Guidelines recommend you don't use **`void`** to specify an empty formal parameter list. For more information, see [C++ Core Guidelines NL.25: Don't use `void` as an argument type](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl25-dont-use-void-as-an-argument-type).
20+
1921
## Example
2022

2123
```cpp
2224
// void.cpp
25+
26+
void return_nothing()
27+
{
28+
// A void function can have a return with no argument,
29+
// or no return statement.
30+
}
31+
2332
void vobject; // C2182
2433
void *pv; // okay
2534
int *pint; int i;
26-
int main() {
35+
int main()
36+
{
2737
pv = &i;
28-
// Cast optional in C required in C++
38+
// Cast is optional in C, required in C++
2939
pint = (int *)pv;
3040
}
3141
```

0 commit comments

Comments
 (0)