#include<bits/stdc++.h> using namespace std; //函数的定义 int add(int num1,int num2) { int sum = num1 + num2; return sum; } void swap(int num1, int num2) { cout << "交换前:" << endl; cout << "num1 = " << num1 << endl; cout << "num2 = " << num2 << endl; int temp = num1; num1 = num2; num2 = temp; cout << "交换后:" << endl; cout << "num1 = " << num1 << endl; cout << "num2 = " << num2 << endl; //return ; 当函数声明时候,不需要返回值,可以不写return } int main() { //函数的调用 int a1=add(2,3); cout<<a1<<endl; //函数值传递 //函数的形参发生改变不影响实参 int a = 10; int b = 20; swap(a, b); cout << "main中的 a = " << a << endl; cout << "main中的 b = " << b << endl; system("pause"); return 0; }