FLIP CLASS
T O P I C : T H E P R E - P R O C E SS E R D I R E C T I V E
2
#include <stdio.h>
#define PI 3.14
int main() {
printf("The value of PI is %.2f\n",
PI);
return 0;
} YOUR CODE
3
LINKERS EXAMPLE
Main.c
#include <stdio.h>
Math.c
int add(int, int);
int add(int a, int b) {
int main()
{
return a + b;
int result = add(3, 4); }
printf("The sum is: %d\n", result);
return 0;
4
PRE-PROCESSOR DIRECTIVE
• FILE INCLUSION
• MODULARITY
• DEBUGGING
AND CONDITIONAL CODING
• MACRO DEFINATION
CONTENT
6
FILE INCLUSION
#include <stdio.h> // Content of stdio.h is copied here during
preprocessing
int main() {
#define printf(...) ...
printf("Hello World\n");
int main() {
return 0;
printf("Hello World\n");
}
return 0;
7
#include <stdio.h>
#define DEBUG
int main() {
printf("Program started.\n");
#ifdef DEBUG
printf("Debug mode enabled.\n");
#endif
printf("Program running...\n");
DEBBUGING
return 0;
8
MODULARITY
// file: main.c // file: math_operations.h
#include <stdio.h> #ifndef MATH_OPERATIONS_H
#include "math_operations.h" #define MATH_OPERATIONS_H
int main() { Int add(int a, int b)
int result = add(5, 3); { return a + b; }
printf("The result is: %d\n", result); Int subtract(int a, int b) {
return 0; return a - b;
} } #endif
9
MACROS
#define PI 3.14
printf("Area of circle: %f\n", PI * r * r);
10
THANK YOU