What happens to memory of variable after loops? (C++)
c++, memory
Solution
It will be deallocated if declared on stack (i.e. via `int x = ...`) and when the variable leaves its scope. It won't be deallocated if declared on heap (i.e. via `int *x = new int(...)`). In that case you have to explicitely use `delete` operator.
Problem
i'm trying to understand how C++ works. When u declare a new variable (int x) within a loop, for example within a for-loop. Memory is allocated to the variable x within the loop, but what happens to that memory after exiting the for-loop? My understanding from a friend is that Java will automatically de-allocate the memory, but what about C++? Thanks.