I'm trying to understand why the output file sizes are significantly different when using a C and a C++ compiler.
I was writing a small hello world program in C and C++, I noticed that in C version, the size of the executable was 93.7KB and in C++, the size of the same hello world program was 1.33MB. I am not sure why that is. I think it may be because C++ has more libraries and namespaces to use so I removed the using namespace std line and simply used std::cout and still the result was the same.
C
#include <stdio.h> int main() { printf("hello world"); return 0; } // size 93.7KB
C++
#include <iostream> int main() { std::cout<<"Hello world"; return 0; } // size 1.33MB
There doesn't seem to be much difference in the code above. Is there some sort of compiler difference that creates the differing file sizes?
printf(available in C++) will produce a file of similar size to C (for example,-nostdliband-nodefaultlibs.