I know that the code written below is illegal
void doSomething(std::string *s){}
int main()
{
doSomething(&std::string(\"Hello World\"));
retur
Why is taking the address of a temporary illegal?
The scope of temporary variables are limited to some particular method or some block, as soon as the method call returns the temporary variables are removed from the memory, so if we return the address of a variable which no longer exists in the memory it does not make sense. Still the address is valid but that address may now contain some garbage value.