指针作为函数参数

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#pragma warning(disable : 4996)

using namespace std;

void Swap(int *p1, int *p2) {
    int tmp;
    tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
}
int main() {

    int m = 3;
    int n = 5;
    cout <<"变换之前"<< m << " " << n << endl;
    Swap(&n, &m);
    cout << "变换之后" << m << " " << n << endl;


    
    

 

    return 0;

}

posted @ 2022-02-16 16:13  江南王小帅  阅读(57)  评论(0)    收藏  举报