Is the stack allocated at runtime or compile time?
Example:
void main()
{
int x;
scanf("%d", &x);
int arr[x];
}
Stack is allocated at runtime; layout of each stack frame, however, is decided at compile time, except for variable-size arrays.
It must be allocated at run time. Consider the following:
void a( void )
{
int x;
}
void b( void )
{
int y;
a();
}
int main( void )
{
a();
b();
}
The address of the stack-local x in a() will be different between its two invocations. As blinkenlights points out, the layout of each function's stack frame is largely determined at compile time, but the placement of that frame is determined at run time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With