When I write
int main()
{
int j;
}
The memory for j
is allocated at the time of compilation, but when during compilation?
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.