#include <iostream>
using namespace std;
int * Function (int a, int b);
int main()
{
int a = 2;
int b = 7;
int * x = &a;
int * y = &b;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
Function (a , b);
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
Function (a , b);
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
system ("PAUSE");
return 0;
}
int * Function (int a, int b)
{
int pom;
pom = a;
a = b;
b = pom;
}
#include <iostream>
using namespace std;
int Function (int * a, int * b);
int main()
{
int a = 2;
int b = 7;
int * x = &a;
int * y = &b;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
Function (&a , &b);
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
Function (&a , & b);
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
cout << endl << endl;
cout << a << " " << *x << endl;
cout << b << " " << *y << endl;
system ("PAUSE");
return 0;
}
int Function (int * a, int * b)
{
int pom;
pom = *a;
*a = *b;
*b = pom;
}
答案 0 :(得分:1)
你正在混合概念,没有一个功能指针
int * Function (int a, int b);
int Function (int * a, int * b);
这样:
int * Function (int a, int b);
是一个按值2整数取值并返回指向int
的指针的函数和这个
int Function (int * a, int * b);
是一个函数,它使用2个指向int并返回一个int