You should have constchar* p = "old"; on line 18. When you assign a string literal like that, you are getting a pointer to read-only memory, which you can't modify. Or at least, modifying it has undefined behavior. In this situation, your attempt to change it is simply doing nothing.
typedefchar *LPSTR; //Consider LPSTR a synonym for the data type "C string".
void func(int *p)
{
*p = 11;
}
void func1(LPSTR t)
{
cout<<t<<" in function\n";
t = "new";
}
void main()
{
int k=10;
func(&k);
cout<<k<<"\n";
LPSTR p= "old" ;
func1(p);
cout<<p<<"\n"; // Why the value is "old" instead of "new"
}
The above should prove obvious that you did not pass a pointer to a C string. You need:
void func1(LPSTR *t)
And then call this function like this:
func1(&p);
just like you do for the other function.
EDIT: And Zhuge makes a point: Variable p is pointing to read-only characters. The appropriate declaration of p should be constchar *p.