Because you aren't actually changing the characters that make up the string: you are changing the copy of the pointer to the characters that make up the string.
When you call a function and pass a pointer as a parameter, by default C++ passes a copy of the pointer. You can change the pointer within the function, and it will not affect the pointer in the outside world.
To change the data in the outside world, there are a couple of things you can do.
1) Change the data the pointer points at:
void someFunc(char* str)
{
*str = 'X';
}
2) Pass a pointer to a pointer:
void someFunc(char* * pstr)
{
*pstr = "Welcome";
}
3) Pass a reference to the pointer:
void someFunc(char* & str)
{
str = "Welcome";
}
[edit]I HATE MARKDOWN[/edit]
"Do you mean that I have passed a copy of pointer str and "Hello" string as well ?? But I have a misunderstanding, when I used the debugger I have found that both of the two pointers have a the same address, does not that mean that both of them points to the same thing ?"
O...Kay...
We need to talk about what a pointer is, and isn't, and what a variable is.
So let's ignore computers, and talk about cars instead.
We both work in the same building, and it has a car park. So we are heading for home, and reach where you parked your car.
We can point at the car and identify it by saying "that car" - or we can identify the same vehicle by saying "your car" (or "my car" in your case). They are different ways to identify the same vehicle.
If I buy the car ("car A") from you and you come in your your new car ("car B") then we can still identify the old car by pointing at "car A" and saying "that car", but "your car" will now identify a different vehicle - "car B".
In programing terms, the "your car" pointer has changed, but the "that car" pointer has not.
So if we do this:
Car* thatCar = &CarA;
Car* yourCar = &CarA;
printf(thatCar.RegistrationNumber);
printf(yourCar.RegistrationNumber);
We get the same number for each vehicle, indicating it's the same car.
So, you sell me your car and get a new one:
Car* thatCar = &CarA;
Car* yourCar = &CarA;
Car* myCar = yourCar;
yourCar = &CarB;
printf(thatCar.RegistrationNumber);
printf(yourCar.RegistrationNumber);
This time, we get two different vehicle registrations, because changing yourCar does not affect thatCar.
It's the same with your someFunc: the address of the string "Hello" is passed into the function, but not the address of the variable which holds it - str is a local variable and is "thrown away" when the function ends, so changes to str within someFunc do not result in changes to str in Main because they are completely different variables!
If you want to affect the str in Main, then you have to pass through either a pointer to the variable (rather than it's content) or a reference to it.
I know this is complicated, and it's difficult to explain without being able to see when your eyes glaze, over, but...does that make sense?