Assuming you have a typo in the second function.
Are they equivalent?
First function will do virtually nothing meanwhile second function will invoke operator new
which might be overloaded and operator delete
which also might be overloaded. This will allocate dynamic memory and free it eventually.
And what is more important, second function can throw an exception.
Is the memory allocated for the a variable freed after program leaves the if block?
In the first function memory will be freed after leaving the scope if it were allocated. In the second example memory will be freed after execution of delete
operator, but keep in mind that you have a pointer as a local variable which will perform like in first case.