In c/c++, are block-scope variables stacked only if the block is executed?

Suppose this: void func() { ... if( blah ) { int x; } ... } Is the space for x reserved on the stack immediately when func is entered, or only if the block is actually executed? Or is it the compiler's choice? Do C and C++ behave the same about this?

May 26, 2025 - 23:10
 0

Suppose this:

void func()
{
 ...
 if( blah )
 {
  int x;
 }
 ...
}  

Is the space for x reserved on the stack immediately when func is entered, or only if the block is actually executed?
Or is it the compiler's choice?
Do C and C++ behave the same about this?