Home >Backend Development >C++ >What does void mean in C++ and what is its function
In C, void can represent an empty type or specify a function without parameters: Empty type: void represents an empty type that does not contain any members, and is often used for function return types (indicating no return value) and pointer to null types. Parameterless function: void can be used to declare or define a function that does not receive any parameters, for example: void printMessage() { std::cout << "Hello World!" << std::endl; }.
The meaning and function of void in C
void keyword
In the C programming language, void
is a keyword with two main meanings:
1. Refers to the empty type
void
can represent an empty type, that is, a type that does not contain any members. It is usually used in the following situations:
2. Specify a function without parameters
When declaring or defining a function that does not accept any parameters, you can use the void
key Word to specify without parameters. For example:
<code class="cpp">void printMessage() { std::cout << "Hello World!" << std::endl; }</code>
Function
void
The keyword has the following functions in C:
The above is the detailed content of What does void mean in C++ and what is its function. For more information, please follow other related articles on the PHP Chinese website!