If I am not clear with the question, please have a look at the code below. Why does the test with character work but not the one with integer ? What is this fundamental difference between string literal and array that I'm finding hard to get my head around ?
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;
}