The void function in C does not return any value and is used to perform specific tasks. They are used to print messages, initialize data structures, respond to input, or perform other specific operations that do not return information.
void function in C
void function is a function in C that does not return any value. They are usually used to perform a specific task without caring about the return value.
Using void functions
Using void functions is very simple. The function declaration and definition are as follows:
<code class="cpp">// 函数声明 void function_name(参数列表); // 函数定义 void function_name(参数列表) { // 函数体 }</code>
Example
The following is an example of a void function that prints "Hello World!":
<code class="cpp">#include <iostream> void printHelloWorld() { std::cout << "Hello World!" << std::endl; } int main() { printHelloWorld(); return 0; }</code>
In the main function After calling the printHelloWorld function in , it will print "Hello World!".
When to use void functions
void functions are typically used to perform the following tasks:
Notes
The above is the detailed content of How to use void function in c++. For more information, please follow other related articles on the PHP Chinese website!