Every C program contains one or more functions which are prototyped in standard library header files. To use functions we need to include them in program. This inclusion is done by preprocessor directives #include. Preprocessor when operates on the source code, stumbles upon such #include directives, for ex. #include
/* cprog.c */ #include <stdio.h> int main(void) { printf("Hello World!\n"); return 0; }
In above program, printf() is prototyped in stdio.h header file. Therefore, stdio.h included in program. The system library file, for ex. #include
/* * End of file character. * Some things throughout the library rely on this being -1. */ #ifndef EOF # define EOF (-1) #endif
Preprocessor symbols all begin with ‘#’ character. Basically, these symbols include #include, #define directives, for ex.,
#include <stdio.h> #include <stdlib.h> #define TRUE 1 #define FALSE 0 #define SIZE 512 #define MAX(a,b) ((a) > (b) ? (a) : (b)) /* Macro */
All preprocessor directives play textual substitution in program. #include directive includes contents of standard library file in program, #define directives, for ex.,
#define SIZE 512
replaces every occurrence of SIZE with value 512, #define macros, for ex.,
#define MAX(a,b) ((a) > (b) ? (a) : (b))
inserts replacement text ((a) > (b) ? (a) : (b)) wherever MAX(a,b) appears in program. Besides, conditional compilation makes compiler see what fragment of code to compile and what to skip. For ex.,
#if constant_expression linux_ver1(); #elif constant-expression linux_ver2(); #else unix_os(); #endif
Every #if construct ends with it’s matching #endif construct. Notice that constant_expression above identifies #define symbols , macros or literal constants. Any variables whose value can’t be ascertained during compile time aren’t valid candidates. Preprocessor doen’t compute the expressions. therefore, C program variables can’t be valid constant expressions.
Sanfoundry Global Education & Learning Series – 1000 C Tutorials.
- Watch Advanced C Programming Videos
- Check Computer Science Books
- Apply for C Internship
- Practice Computer Science MCQs
- Apply for Computer Science Internship