Wednesday, 21 June 2023

Including files in C

What is including files in C?

The preprocessor directive #include is used to include or cover a file into the birthplace or source code. We have already used this command or directive to include header files in our plan or programs. The filename should be within viewpoint or angle brackets or double repeat or quotes. The syntax is –

#include <filename>

#include “filename”

Preprocessor, define, files in C, C language
C program library files Image-1

The preprocessor return or replaces the #include directive or command by the satisfy or contents of the specified file. After including the file, the total or entire contents of file can be used in the plan or program. If the filename is in double repeat or quotes, first it is look or searched in the current directory (where the birthplace or source file is present), if not found there then it is look or searched in the include directory. If the filename is with viewpoint or angle brackets, then the file is searched in the quality or standard include directory only. The statement or specification of standard or quality include directory is execution or implementation defined.

Include files can be fixed or nested i.e. an included file can carry or contain another #include directive.

1.1 The #define and #undef Directives

The #define directive is the most usual or common preprocessor directive, which tells the preprocessor to return or replace every event or occurrence of a particular character string (that is, a macro name) with a define or specified value (that is, a macro body).

The syntax for the #define directive is

                #define macro_name macro_body

Here macro_name is a proof or identifier that can carry or contain letters, numerals, or underscores. Macro_body may be a string or a data item, which is old or used to substitute each macro_name found in the program or plan.

As bring up or mentioned earlier, the running or operation to replace event or occurrences of macro_name with the value define or specified by macro_body is known as macro exchange or substitution or macro expansion.

The value of the macro body define or specified by a #define directive can be any character string or number.

                                #define STATE_NAME “Texas”

Then, during preprocessing, all event or occurrences of STATE_NAME will be replaced by “Texas”.

                #define SUM (12+8)

On the other hand, you can use the #undef directive to separate or remove the definition of a macro name that has been previously defined.

The syntax for the #undef directive is

                                #undef macro_name

Here macro_name is an identifier that has been previously explain or defined by a #define directive.

The #undef directive “undefines” a macro name.

For case or instance, the following segment of code:
#define STATE_NAME “Texas”
printf (“I am moving out of %s. \n”, STATE_NAME);
#undef STATE_NAME


Computer stuff kit tricks of Topics 64.