Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Header Files & Multiple | C Programming Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. C Programming Fundamentals

Lesson 27 of 50

·c

Header Files & Multiple Translation Units

11 mins

Course progress54%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Header files (`.h`) expose **public interfaces**; source files (`.c`) provide implementations.
  • Include guards (`#ifndef … #define … #endif`) prevent duplicate inclusion.
  • Separate compilation speeds up builds and enables modular testing.
  • The linker resolves external symbols from the object files.

A translation unit is a source file after preprocessing. Splitting a project into multiple .c files improves modularity.

Typical layout:

project/
├─ src/
│   ├─ main.c          // contains main()
│   └─ utils.c         // implementation of utility functions
├─ include/
│   └─ utils.h         // declarations for utils.c
├─ Makefile
└─ README.md

utils.h provides function prototypes and type definitions. utils.c includes the header and defines the functions. The compiler compiles each .c file separately, then the linker combines the object files.


⚡ Build with gcc

gcc -Iinclude -c src/utils.c   # produces utils.o
gcc -Iinclude -c src/main.c    # produces main.o
gcc -o myprogram main.o utils.o

📦 Using a Makefile

CC=gcc
CFLAGS=-Wall -Wextra -Iinclude
OBJ=main.o utils.o

myprogram: $(OBJ)
	$(CC) -o $@ $^

%.o: src/%.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f $(OBJ) myprogram
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from C Programming FundamentalsBrowse activities
Previous lessonPreprocessor DirectivesContinue to lesson 28Makefiles – Building Large ProjectsBack to C Programming Fundamentals curriculum