The #include directive in C is used to include the contents of one file into another during the preprocessing phase of compilation. This allows for modular programming and code reuse, enabling you to separate code into multiple files and include them as needed.
#include <filename>
or
#include "filename"
here, Angle Brackets < >: Used for standard library headers or system headers, Double Quotes " ": Used for user-defined or local header files.
#include <stdio.h>
This includes the standard input/output library, allowing you to use functions like printf and scanf.
#include "myheader.h"
This includes a local file named myheader.h from the same directory or a specified include path.
#includeFile: main.c
#include <stdio.h>
#include "myfunctions.h"
int main() {
printHello();
return 0;
}
File: myfunctions.h
#ifndef MYFUNCTIONS_H
#define MYFUNCTIONS_H
void printHello();
#endif
File: myfunctions.c
#include <stdio.h>
#include "myfunctions.h"
void printHello() {
printf("Hello, World!\n");
}Using #include effectively helps in organizing code, improving readability, and enabling code reuse across different parts of a project.