If I have a function c
int foo(int input) { int x = 5; if( input == 0 ){ int y = 6; } else { int z = 7; } }
I know that the stack pointer is set up when we enter the function, and this makes space for the operator int x. And I know that ythey zexist only within their respective blocks. But when and how is space allocated to them?
int x
y
z
It is up to the compiler if space lasts, at least for the life of the variable.
, . , . , , , .
: , C ( ++) . , , .
int foo(int input) { // BLOCK 1 int x = 5; if( input == 0 ) { // BLOCK 2 int y = input * (x + 6); // other code here } else { // BLOCK 3 int z = input + x; // other code here } }
, :
x BLOCK 1 (BLOCK 2 BLOCK 3). y BLOCK 2. z BLOCK 3.
x
BLOCK 1
BLOCK 2
BLOCK 3
, , . , ( ), (, ), , , - .