When you divide a large program into a bunch of smaller programs, you’re doing nothing more than rearranging and organizing your instructions. Unfortunately, a large program written as one long list of instructions is barely any smaller than the same large program divided into multiple subprograms. Because the larger a program gets, the harder it can be to understand, programmers found a way to take subprograms out of the main program file and store them in separate files.
Now instead of a program consisting of a single, massive file, it can consist of two, three, or even several thousand separate files.
By storing subprograms in separate files, reading and understanding your program is much simpler. Instead of scrolling through one massive file that contains your main program and all of its subprograms, you can just open the file that contains the subprogram you want.
A second advantage is that storing subprograms in separate files also lets you reuse subprograms. By storing commonly used subprograms in files, you can create libraries of useful subprograms, copy them to another computer, and reuse them in other programs.
One file might contain subprograms that calculate different mathematical equations, and a second file might contain subprograms that display graphics on-screen. By creating and reusing libraries of subprograms, you can keep your main program size to a minimum.
Technical Stuff If you ever look at the structure of a typical C++ program, you might see code that looks like this:
#include <stdio.h>
#include <iostream.h>
int main()
{
return 0;
}
The two #include commands simply tell the computer to use (or include) the subprograms stored in the separate files named iostream.h and stdio.h.
