Yes, your concept is completely wrong.
In your Alter() function, which I simplify here (to remove extraneous output unrelated to your question)
void Alter(char* X, char* Y)
{
char* T;
T = X;
X = Y;
Y = T;
cout<<X<<"&"<<Y<<endl;
}
X and Y are both pointers and they are passed by value. So the assignments X = Y and Y = T are not visible to the caller i.e. to main(). Specifically, the assignments in the function (X = Y and Y = T) have no effect that is visible to main().
However, X and Y each point to (or can be used to refer to) something - in your code, the first character of the arrays in main(). Those somethings, in the function, are *X and *Y. One archaic description - which seems to be what your course book is using - is that they are the things "passed by reference".
If we were to change Alter() to make assignments to *X and *Y viz;
void Alter(char* X, char* Y)
{
char T; // note the missing * here relative to your code
T = *X; // note the added * in this line
*X = *Y; // note the added *s in this line and the next
*Y = *T;
cout<<X<<"&"<<Y<<endl; // this statement is unchanged
}
In this case, the output would be
Sirst&Fecond
Sirst&Fecond
(i.e. the first characters of the arrays swapped, and that effect is visible to main()).
We could also change Alter() to
void Alter(char*& X, char*& Y) // note the ampersands here
{
char* T;
T = X;
X = Y;
Y = T;
cout<<X<<"&"<<Y<<endl;
}
In C++, the ampersands here mean that X and Y are references to pointers. So the assignments in this function would be visible to the caller.
However, your example main() (which again I simply to remove extraneous output) will not compile with using this function
int main() // main() returns int in standard C++, not void
{
char X[]="First", Y[]="Second";
Alter(X,Y);
cout<<X<<"*"<<Y;
}
This will not compile because X and Y in main() are arrays, and arrays ARE NOT pointers - so they cannot be passed to a function that expects to be passed references to pointers. This means that your function Alter() cannot be used to swap the arrays in main().