The C Preprocessor
The C Preprocessor
• This directive instructs the C preprocessor to scan the included file before proceeding with the
current file.
• The first statement searches for an include file by name systemfile in the standard system
directories .
• The second statement is used for including header files defined by a programmer in the current
directory. The preprocessor will first search for the file in the directory where the program exists,
and then if it does not find such a include file, then it looks for it in the standard system directories.
This preprocessor directive must appear in your program before any of the definitions contained in
the header file are referenced. The preprocessor searches for this file on the system and includes
its contents to the program at the point where the #include statement appears.
Conditional compilation
• Macros are used for assigning symbolic names to program constants, when these
are repetitively used within a program.
• #define macro is the most commonly used macro. It's purpose is to define a
name for a value or constant.
• The #define macro makes a program extendable, meaning the value of the
definition can be changed in just one place, and this gets reflected in all the
places the value is used.
#define MIN 0
#define MAX 10
#define TRUE 1
#define FALSE 0
int main() {
int a;
int okay = FALSE;
while(!okay) {
printf("Input an integer between %d and %d: ", MIN, MAX);
scanf("%d", &a);
if(a>MAX) {
printf("\nToo large.\n");
}
else if(a<MIN) {
printf("\nToo small.\n");
}
else {
printf("\nThanks.\n");
okay = TRUE;
}
}
return 0;
}
#include <stdio.h>
main()
{
int i;
i=max*max;
printf("%d",i);
}
#include <stdio.h>
START
PRINT
END