In C programming, the #include directive is a preprocessor directive used to include the contents of another files into the current file.
This is typically used to include header files ".h" that contain declarations of functions, variables, and other entities that are defined elsewhere.
Using including `user-define` headers files, we can reuse code across multiple source files without duplicating the code and prevent naming conflicts as well.
#include <filename> or #include "filename"
"filename" specifies a user-defined header file to be included. The double quotes " " indicate that the file should be searched for in the current directory first, then in other specified directories.
#include <stdio.h>
This includes the standard input-output header file "stdio.h", which contains declarations for functions like "printf()" and "scanf()".
#include "yourHeader.h"
This includes a user-defined header file "yourHeader.h" located in the current directory or specified directories.
This file might contain custom function prototypes, constants, or other declarations used in the program.
#include "your_functions.h" int main() { int result = add(4, 3); printf("The sum is: %d\n", result); return 0; }
// your_functions.h #ifndef YOUR_FUNCTIONS_H #define YOUR_FUNCTIONS_H int add(int a, int b); #endif
#include <stdlib.h> #include <string.h>
standard library headers "stdlib.h" and "string.h", which provide functions and definitions for "memory allocation", "string manipulation", and "other utilities".
#include <stdio.h> #include <stdlib.h> int main() { printf("Hello, World!\n"); return 0; }
"#include" is a fundamental directive in C programming for including header files, which in turn provides declarations necessary for your program's functionality, whether they're standard library headers, user-defined headers, or nested headers.