int evilFunction() {
int* i = new int(9);
return *i;
}
int main() {
int num = evilFunction();
return 0;
}
What causes memory leak in this example ?
I thought when the functions returns value 9, immediately the pointer (i) and value 9 (*i) will be deallocated from the memory only num ( primitive-variable ) and its value 9 will stay in the memory.