C #include Directive

Intermediate
6 min read
Updated: Nov 2026
1 example

What Is #include Directive?

#include copies another file's text at that point. Use angle brackets <stdio.h> for system and library headers (searched in system paths) and quotes "mylib.h" for your own headers (searched in the current project first). Headers usually contain declarations, macros, and types, not function bodies.

Remember
#include <stdio.h>      /* system / standard header */
#include "util.h"       /* your project header      */

Cheat Sheet

Keep these facts handy while you work with #include Directive in C.

TopicDetail
< >System include paths
" "Current directory first, then system paths
Add pathgcc -I include_dir
NestingHeaders can include headers

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: #define Directive.

Example 1 — A tiny project header

Save the header as mathutil.h next to main.c.

C
/* mathutil.h */
#ifndef MATHUTIL_H
#define MATHUTIL_H
static inline int square(int n) { return n * n; }
#endif

/* main.c */
#include <stdio.h>
#include "mathutil.h"

int main(void) {
    printf("square(6) = %d\n", square(6));
    return 0;
}

How It Works

  1. <stdio.h> comes from the compiler's standard include path.
  2. "mathutil.h" is found in the same folder as main.c.
  3. The header guard prevents problems if the header is included twice.

Edge Cases & Pitfalls

Check these before relying on #include Directive in real programs.

code

Including .c files

Including a .c file duplicates definitions and breaks linking. Include only headers.

circ

Circular includes

Two headers including each other cause missing-type errors. Use forward declarations and guards.

Key Takeaways

  • < > for libraries.
  • " " for your files.
  • Headers declare; sources define.

One line: #include copies another file's text at that point.

Frequently Asked Questions

Angle brackets search the system include directories; quotes search the including file's directory first, then fall back to the system directories.
Yes, if it has include guards (or #pragma once), which skip the repeated contents.
Continue with "C #define Directive" next. Define named constants and macros with #define. The C Preprocessor hub lists every topic in order.

Next: #define Directive

Define named constants and macros with #define.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful