What Are Header Files?
Header files (
.h) declare the interface of your code — function prototypes, type definitions, constants, and macros. Other .c files #include them to use your code without seeing the implementation.Anatomy of a Good Header
c
c
Include Guards vs #pragma once
c
What Goes in a Header
| ✅ Put in header | ❌ Don't put in header |
|---|---|
| Function prototypes | Function bodies |
typedef and struct definitions | Variable definitions |
#define constants | static variables |
extern variable declarations | Large data arrays |
static inline functions | — |
Forward Declarations
Declare a type exists without defining it — useful for breaking circular dependencies:
c
Summary
- Headers define the interface, source files define the implementation
- Always use include guards or
#pragma once - Never put variable definitions in headers
- Use forward declarations to break circular dependencies