Home > Article > Backend Development > How to call void function in c++ later
Call void function in C: Define function: void function_name(parameter_list) {/Function code/}Call function: function_name(argument_list);
How to call the void function in C
The void function is a function that has no return value type. In C, you can call a void function by following the steps below:
1. Define the function
First, you need to define a void function. The syntax of void function is as follows:
<code class="cpp">void function_name(parameter_list) { // 函数代码 }</code>
where function_name
is the function name, parameter_list
is the function parameter list (optional).
2. Call the function
To call the void function, you can use the following syntax:
<code class="cpp">function_name(argument_list);</code>
Among them, argument_list
is given Defines the list of actual parameters of the function, which should match the type and number of parameters in the function parameter list.
Example
The following is a sample code using the void function:
<code class="cpp">void print_hello() { std::cout << "Hello, world!" << std::endl; } int main() { print_hello(); return 0; }</code>
In this example, print_hello
is a void function, which prints "Hello, world!". In the main
function, the print_hello
function is called, causing it to execute and print its message.
The above is the detailed content of How to call void function in c++ later. For more information, please follow other related articles on the PHP Chinese website!