I know that whenever we allocate something into the heap, we must delete it. So I have a question, which I'll explain with help of an example.
Let's say size
is a function that uses the new
operator.
int size (...){
...
int *p = new int[1];
*p = 5;
...
return *p;
}
I have allocated some memory in the heap
so I must delete it, but if in my main
function I do this...
int main(){
int i = 0;
if (i < size(...)){ // <- here
...
}
}
As you can see I am not assigning size(...)
to anything. My question is can we deallocate memory in such a situation, if yes then how?