In case 1, a global variable is assigned to a variable, but declared.
But in the second case, a global variable is assigned ( which has already been declared) with the return value foo ().
The formation of the data section, the text section occurs at compile time.
Global variables will be in the data section (the bss or initialized data section), so is foo () not being called correctly at compile time? and the return value of foo () at compile time is unknown.
But the second case, when the text section is executed, gvar assigned the return value of foo (). It's really.
source share