Oct 012013
 

Interview Question…

I have following code snippets…

Code snippet 1
int arr[1000000];
int main()
{   
	return arr[0];
}
Code snippet 2:
int arr[1000000] = {10};
int main()
{   
	return arr[0];
}

After compilation of the above snippets the output exe differs in size. The second snippet’s executable is much bigger in size than the first snippet’s executable. See screenshot…

image

Why?

 

  3 Responses to “C/C++ Interview Question: Why Executable file differs in size”

  1. And only for global variables???

  2. Is it because it embed 1000000 X 4 byte long array with initial value as 10 in exe itself? That’s awful!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.