+ 1
Does the memory allocated to a local variable get deallocated automatically after its scope ends?
4 odpowiedzi
+ 2
Unless the variable is static, memory will be deallocated, thus losing its value at the end of its scope. Of course, when calling again, that memory is reallocated.
+ 1
Or is it reallocated at each call and deallocated after the scope ends ?
+ 1
Actually it depends. If you just declare a variable inside a function (int b = 3;), the memory assigned to that variable will be freed when it goes out of scope. If you use new (int *b = new int[3];), the memory has to be freed explicitly by using delete (delete [] b;).
0
no... basically it remains to that memory so that you can recall it at any time during program