Q.The textbook explains the #include directive, which can take the form #include "file name" (a library file, with double quotation marks) or #include <file name> (without double quotation marks). It notes that an include file can include other files but a file cannot include itself, and gives the following example of including files in a program:
#include <stdio.h>
#include <SYNTAX.C>
#include <STAT.C>
#include <TEST.C>
#define M 100
main()
{
___
___
___
}
#include <stdio.h>
#include <SYNTAX.C>
#include <STAT.C>
#include <TEST.C>
#define M 100
main()
{
___
___
___
}
[!TLDR]
#include tells the preprocessor to copy the contents of another file into the current program at that point, before compilation.
An external file that contains functions or macro definitions can be brought into a program with the #include directive, so those definitions do not have to be rewritten. It has two forms:
#include "file name"
#include <file name>
The double-quotation form names a library file that contains the required function definitions; the angle-bracket form is used without double quotation marks (typically for standard system headers). An include file may itself include other files, but a file cannot include itself. In the example, stdio.h is the standard input/output header, while SYNTAX.C, STAT.C and TEST.C are illustrative user files (containing syntax, statistical and test functions respectively); #define M 100 then defines the constant M, and main() would use these facilities. Because SYNTAX.C, STAT.C and TEST.C are hypothetical files used only to teach the directive, this listing is a conceptual skeleton rather than a program that compiles as it stands.
[!ANSWER]
The #include directive inserts an external file's contents into the program: #include <stdio.h> brings in the standard I/O functions and the three user files supply their own functions, while #define M 100 defines the constant M for use inside main().
[!NOTE]
The textbook's corrigendum (pp.578-580) corrects the three include lines to the angle-bracket form shown above (#include <SYNTAX.C>, #include <STAT.C>, #include <TEST.C>).
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.