C++ 函数

C++ 函数
函数是一组一起执行一个任务的语句。每个 C++ 程序都至少有一个函数,即主函数 main() ,所有简单的程序都可以定义其他额外的函数。

您可以把代码划分到不同的函数中。如何划分代码到不同的函数中是由您来决定的,但在逻辑上,划分通常是根据每个函数执行一个特定的任务来进行的。

函数声明告诉编译器函数的名称、返回类型和参数。函数定义提供了函数的实际主体。

C++ 标准库提供了大量的程序可以调用的内置函数。例如,函数 strcat() 用来连接两个字符串,函数 memcpy() 用来复制内存到另一个位置。

函数还有很多叫法,比如方法、子例程或程序,等等。

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 void printstar(void)
 6 {
 7     cout <<"**********************"<<endl;
 8 }
 9 void print_message(void)
10 {
11     cout <<"Welcome to c++!"<<endl;
12 }
13 
14 int main(void) {
15     printstar();
16     print_message();
17     printstar();
18     return 0;
19 }
原文地址:https://www.cnblogs.com/borter/p/9401029.html