Skip to content

Add examples for void type in cpp (#4331) #4332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/cpp/void-cpp.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: void (C++)"
title: "void (C++)"
ms.date: 10/15/2021
ms.date: 12/13/2022
f1_keywords: ["void_cpp"]
helpviewer_keywords: ["void keyword [C++]", "functions [C++], void", "pointers, void"]
ms.assetid: d203edba-38e6-4056-8b89-011437351057
Expand All @@ -16,16 +16,26 @@ In C++, a **`void`** pointer can point to a free function (a function that's not

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

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

## Example

```cpp
// void.cpp

void return_nothing()
{
// A void function can have a return with no argument,
// or no return statement.
}

void vobject; // C2182
void *pv; // okay
int *pint; int i;
int main() {
int main()
{
pv = &i;
// Cast optional in C required in C++
// Cast is optional in C, required in C++
pint = (int *)pv;
}
```
Expand Down