Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <iostream>
using namespace std;
void swap(int &x, int &y);
void swap_pnt(int *x, int *y);
int main()
{
int i, j;
i = 19283;
j = 48581;
cout << "i:" << i << endl;
cout << "j:" << j << endl;
swap(i, j);
cout << "i:" << i << endl;
cout << "j:" << j << endl;
for (int i = 0; i < 22; i++) {
cout << "-";
}
cout << "\n";
int w, y;
w = 10293;
y = 299393;
cout << "i:" << w << endl;
cout << "j:" << y << endl;
swap_pnt(&w, &y);
cout << "i:" << w << endl;
cout << "j:" << y << endl;
return 0;
}
//参照
void swap(int &x, int &j)
{
cout << "値を交換します・・・" << endl;
int t;
t = x;
x = j;
j = t;
}
//ポインタ
void swap_pnt(int *x, int *y)
{
cout << "値を交換します" << endl;
int t;
t = *x;
*x = *y;
*y = t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment