What happens if I include iostream
or any other header file twice in my file?
I know the compiler does not throw error.
Will the code gets added twice
Header files are simple beasts. When you #include
all that happens is that the contents of header
basically get copy-pasted into the file. To stop headers from being included multiple times, include guards
are used, which is why in most header files you'll see something akin to
#ifndef SOME_HEADER_FILE_GUARD
#define SOME_HEADER_FILE_GUARD
//Contents of Header
#endif