如果我不清楚这个问题,请查看下面的代码。为什么字符测试有效,而整数测试无效?我发现很难理解的字符串文字和数组之间的根本区别是什么?
using namespace std;
void fun(int &x)
{
cout << x << " okk" << endl;
}
void test (int* &a, int* &b) {
int* temp = a;
a = b;
b = temp;
//cout << *a << " " << &a << endl;
}
void test (char* &a, char* &b) {
cout << &a << " " << &b << endl;
char * temp = a;
a = b;
b = temp;
//cout << *a << " " << &a << endl;
}
int main()
{
char *s = "help";
char *t = "me";
char *u = "help";
cout << s << " " << t << " " << u << endl;
/*char *temp = s;
s = t;
t = temp;
*/
test (s,t);
cout << s << " " << t << endl;
int a[10] = {1,2,3,4,5,6,7,8,9,10};
int b[10] = {11,12,13,14,15,16,17,18,19,20};
cout << *a << " " << *b << endl;
test (a,b);
cout << *a << " " << *b;
}