Function declaration and call flow

#include
//function declaration
int sum(int n);
//90 becomes the actual parameter-the actual number, n represents the formal parameter,

int main(){ //Using sum(90), 90 will be passed to the sum function n //After the execution is completed, return to sum //The function call is. The actual parameter is to the value, and there are several formal parameters to pass the actual Join in.


std::cout<<sum(90)<<std::endl;

}
//Function declaration, how to put the function definition behind: add function declaration-write the function one more time and put it in the header file
//Transmission process: find the function parameter, then use it in the function, and finally return
// Normally it is a function definition call, but the function declaration is
//function declaration-calling function-function definition
//function definition➡️Type function name (function parameter)
//You can also int max(int,int,int) only write type
int sum(int n){ int s=0; for(int i=1;i<=n;i++){ s+= i;


}
return s;
    }

```cpp
在这里插入代码片
```#include<iostream>
//函数声明
int sum(int n);
//90成为实参——实际的数,n表示形参形式参数,

int main(){
    
    
    //使用sum(90),就会把90传递给sum函数n
    //执行完之后在返回到sum
    //函数调用是.实参到值,有几个形参就传递实参过去.
    
    std::cout<<sum(90)<<std::endl;
}
//函数声明,函数定义怎么放在后面:加函数声明——把函数在多写一次放在头文件哪里
//传递流程:找函数参数,然后在放在功能内使用,最后返回
//正常是函数定义调用,但函数声明是
//函数声明——调用函数-函数定义
//函数定义➡️类型   函数名(函数参数)
//也可以int max(int,int,int)只写类型
int sum(int n){
    
    
    int s=0;
    for(int i=1;i<=n;i++){
    
    
        s+= i;
        
    }
    return s;
        }

Guess you like

Origin blog.csdn.net/qq_45035858/article/details/113063128