I came across this question and I would like to know why the address of a non constant string created on the stack of a method returns a constant pointer when its address is requested. I have copy-pasted the code sample used there
void myfunc(string*& val)
{
// Do stuff to the string pointer
}
int main()
{
// ...
string s;
myfunc(&s);
// ...
}
My question is that &
returns the address of a variable. So In the above case the std::string s
is a non constant
then why is it returning its address as a constant ? What I want to know is why the address of the non-constant string is returned as a constant address. Are the addresses of all objects created on the stack constant ?