Home  >  Article  >  Backend Development  >  How to call void function in c++ later

How to call void function in c++ later

下次还敢
下次还敢Original
2024-05-09 03:18:15432browse

Call void function in C: Define function: void function_name(parameter_list) {/Function code/}Call function: function_name(argument_list);

How to call void function in c++ later

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn