Home > Back-end >  Local variables defined in the function called each other
Local variables defined in the function called each other

Time:12-12

Is the following code:
Void (A) {int A=1; (B); }
Void (B) {int B=1; (A); }
In the process of the call, please. A, b will be released? Or will produce many of the local variable a, b?
Thank you!

CodePudding user response:

Is released, the local variables of type int is reserved space in the stack,
See the corresponding assembly code will thoroughly understand,

The variable usually includes function arguments and function in the stack declared temporary variables,
The basic variables of the stack exit its scope, who did not perform a piece of code to release/destroy/destructor of memory, it occupies only is no one to stay at the top of the current stack of several legacy can be covered by subsequent pressure stack, useless data,
And the class variables in the stack exit its scope, will automatically perform its destructor,...

CodePudding user response:

Local variables at the end of the function of memory automatically release

CodePudding user response:

The
refer to the original poster m0_49891037 response:
with the following code:
Void (A) {int A=1; (B); }
Void (B) {int B=1; (A); }
In the process of the call, please. A, b will be released? Or will produce many of the local variable a, b?
Thank you!

The lifecycle of the local variable from the function defined in the beginning, end of the guide function calls, call a function, repeatedly in a local variable in a function are the same, call a few times there are several life cycle

CodePudding user response:

Indirect recursion and recursive, a function without end does not release its local variables, will produce a lot of a, b, a copy of the until the stack overflow,
  • Related