The preprocessor in c programming tutorial is a part of the compiler which performs basic preparatory operations (conditionally compiling code, including files, etc...) in a code before the compiler starts compiling. These transformations are lexical, meaning that the output of the preprocessor is still in form of text.
The basic compilation of every C program is passed through a Preprocessor. The Preprocessor tries to find out specific instruction throughout the whole C program which are called Preprocessor directives that it can understand. Preprocessor directives always begin with the # (hash) symbol. C++ compilers use the same C preprocessor..
The preprocessor is usually use to include another file in C language:
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
The preprocessor replaces the line #include <stdio.h> with the text of the file 'stdio.h', which then defines the scanf() or printf() function among other data.
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
The preprocessor replaces the line #include <stdio.h> with the text of the file 'stdio.h', which then defines the scanf() or printf() function among other data.
Some of the advantages of preprocessor in c programming language includes:
Easier programs development
easier to read,
easier to modify
C code more transportable between different processor architectures.
Easier programs development
easier to read,
easier to modify
C code more transportable between different processor architectures.
Preprocessor directives:
These preprocessor directives of c programming go on only across a single line of code until a newline character is found where the preprocessor directive ends. Note that Semicolon (;) will be always absent at the end of the directives. The only way a preprocessor directive can extend through more than one line is by preceding the newline character at the end of the line by a backslash (\).
Some of the preprocessor directive in C programming language are given below:
#include
#define
#undef
#if
#ifdef
#ifndef
#error
__FILE__
__LINE__
__DATE__
__TIME__
__TIMESTAMP__
pragma
# macro operator
## macro operator
Some of the preprocessor directive in C programming language are given below:
#include
#define
#undef
#if
#ifdef
#ifndef
#error
__FILE__
__LINE__
__DATE__
__TIME__
__TIMESTAMP__
pragma
# macro operator
## macro operator
To define preprocessor directive we can use #define.
The syntax is:
The syntax is:
#define identifier replacement
Example:
1 #define TABLE_SIZE 100
2 int table1[TABLE_SIZE];
3 int table2[TABLE_SIZE];
int table2[TABLE_SIZE];
1 #define TABLE_SIZE 100
2 int table1[TABLE_SIZE];
3 int table2[TABLE_SIZE];
int table2[TABLE_SIZE];
After the preprocessing ,the preprocessor replaces TABLE_SIZE, so the code becomes equivalent to:
1 . int table1[100];
2 . int table2[100];
1 . int table1[100];
2 . int table2[100];
0 comments:
Post a Comment