When is memory allocated during compilation?

后端 未结 8 1887
说谎
说谎 2020-12-18 15:18

When I write

int main()
{
    int j;
}

The memory for j is allocated at the time of compilation, but when during compilation?

8条回答
  •  [愿得一人]
    2020-12-18 15:23

    It is up to the compiler where to place j. Usually local variables are placed on the stack and as such for your particular example, the compiler will probably reserve the space on the stack for the duration of the main function. Note that this is different from global variable memory, which may receive its own memory.

提交回复
热议问题