#include <iostream> using namespace std; int max(int num1, int num2); void swap(int *x, int *y); void swap(int &x, int &y); int main(){ cout << "hello world" << endl; int num1 = 100; int num2 = 200; int v_max = max(num1, num2); cout << v_max << endl; //cout << "before swap " << num1 << " " << num2 << endl; //swap(&num1, &num2); //cout << "after swap " << num1 << " " << num2 << endl; cout << "before swap " << num1 << " " << num2 << endl; swap(num1, num2); cout << "after swap " << num1 << " " << num2 << endl; } int max(int num1, int num2) { if (num1 > num2) return num1; else return num2; } void swap(int *x, int *y) { int temp; temp = *x; /*保存指针*/ *x = *y; *y = temp; return; } void swap(int &x, int &y) { int tmp; tmp = x; x = y; y = tmp; return; }
时间: 2024-11-08 23:56:47