Discuss the use of #define and #include in C programming

10 a]Discuss the use of #define and #include in C programming

SL NOPreprocessorsyntaxDescription
1Macro#defineThis macro defines constant value and can be any of the basic data types.
2Header file inclusion#include<file_name>The source code of the file “file_name” is included in the main program at the specified place

Macro substitution: Macro substitution is a process where an identifier in a program is replaced by a predefined string composed of one or more tokens. The preprocessor accomplishes this task under the direction of #define statement. It takes the following form

#define identifier string

Here the preprocessor replaces every occurrence of the identifier in the source code by the string.
Example:

#define PI 3.14
#define COUNT 100

File inclusion: An external file containing functions or macro definition can be included as a part of program so that we need not rewrite those functions or macro definition. This is achieved by preprocessor directive.

#include”file_name”

Where filename is the name of the file containing the required file. When the filename is included within the double quotation marks, the search for the file is made in first in the current directory and then in the standard directory.

Alternatively

#include<file_name>

In this case file is searched only in the standard directories

Example:

#include<stdio.h>
void main()
{
 clrscr();
}

Leave a Reply

Your email address will not be published. Required fields are marked *