At what exact moment is a local variable allocated storage?

后端 未结 5 789
执笔经年
执笔经年 2020-12-10 15:19

Suppose we have the following:

void print()
{
     int a;  // declaration
     a = 9;
     cout << a << endl;
}

int main ()
{
     print();
}
         


        
5条回答
  •  北海茫月
    2020-12-10 15:41

    This will be compiler dependent, but typically the variable int a will be allocated on the stack at the time the function is called.

提交回复
热议问题