No this will apsolutley not work, because you're returning a local scoped pointer. which actually isn't a pointer at all!
When functin return local int the int is dead, so your return will be also dead.
Here is an example that would work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int* f()
{
returnnewint;
}
int main()
{
//... somewere in the code later.
int* pVariable = f();
// ... somewere in the code later
delete pVariable;
return 0;
}