When I write
int main()
{
int j;
}
The memory for j
is allocated at the time of compilation, but when during compilation?
Compilation generates the executable code for a program. Program memory is allocated when that executable code is run.
The memory isn't allocated at the time of compilation, but at runtime. The compiler just generated machine code that will execute your program, actual allocations happen at runtime. In this case the variable isn't used and there won't emitted any code for it.