Though a similar question has been asked Is it possible to deallocate a statically defined array? previously, I have a related query.
int* foo()
{
int arr[3] = {1, 2, 3};
return arr;
}
int bar(const int*)
{
doSomething with int*;
}
int main()
{
bar( foo() );
}
When will the memory allocated to arr
in foo()
be deallocated? Is a statically allocated array like arr
not usually automatic? This syntax seems to work though, so is the memory assigned to arr
only deallocated after the completion of bar()
? Or not even then? If not, how would I free it?
Edit: Sorry, forgot to include main. Yes, this appears to be a duplicate post.