Is the following code snippet correct, or what could be wrong with it?
As I know, memory allocated with new
, will not be erased unless there is a delete
so returning its pointer should be fine?
// Example program
#include <iostream>
#include <string>
int* a()
{
int* aa = new int(1);
*aa = 44;
return aa;
}
int main()
{
int *aa = a();
printf("%d ", *aa);
}