I started with an "empty" program and checked the size of the .exe file produced
int main() { system("pause"); } Exe Size: 58.5 KB (59,904 bytes)
I then added a large array of static variables
int main() { const int BIG_NUMBER = 40000000; static int x[40000000]; system("pause"); } Exe Size: 58.5 KB (59,904 bytes)
Making the array non-static also had no effect. I added some code to (a) make 100% sure the variable is not being optimised away and (b) see if the extra instructions would increase the number of bytes of the .exe
int main() { const int BIG_NUMBER = 40000000; static int x[40000000]; for (int i = 0; i < BIG_NUMBER; ++i) { std::cout << x[i] << std::endl; } system("pause"); } Exe Size: 58.5 KB (59,904 bytes)
Literally not a single byte more. At this point my (stab in the dark) guess is that the .exe requests the OS to allocate the correct amount of memory needed for the static variables when the program starts but this doesn't seem right. What determines the .exe file size?