Header Files

What Is a File Header?

A file header is either a comment block at the top of a source file or the metadata at the start of a binary file. Learn how it differs from a .h header.

On this page
  1. Short answer
  2. A comment block at the top of a source file
  3. The header of a binary file
  4. How it differs from a header file

Short answer

“File header” has two common meanings. In source code, it usually means a comment block at the top of a file that describes it. In a binary file format, it means the fixed bytes at the start of the file that describe what follows. Neither meaning is the same as a .h header file, although the word is shared.

A comment block at the top of a source file

Many teams start each source file with a short comment:

/*
 * File:    parser.cpp
 * Purpose: reads settings from a config file
 * Author:  your name
 * Date:    2026-11-26
 */

The compiler ignores comments. Their job is to help people understand the file, and some projects also keep license notices there.

The header of a binary file

Binary formats often begin with a fixed structure that a program reads first, so it knows how to parse the rest of the file. Two examples:

  • PNG images start with an 8-byte signature. Its values, written in decimal, are 137, 80, 78, 71, 13, 10, 26 and 10. The chunks that describe the image follow it.
  • WAV audio files start with a RIFF header: the four characters RIFF, a size field, and the tag WAVE.

A C or C++ program reads these by opening the file and examining the first bytes. The exact layout depends on the format, so check its specification before writing a parser.

How it differs from a header file

File header Header file (.h)
Where it appears At the top of a file A separate file, pulled in with #include
What it describes The file, or the format of its contents Declarations that other source files need
What the compiler does Ignores the comment; a binary header is data that a program reads Reads its declarations as part of each source file

If you are writing C or C++ and need a place for declarations shared between files, you want a .h file. If you want a note about what a file does, put it in a comment at the top.

The complete guide to header files

C++ Header File Example
Read the guide

Keep exploring

Guides from other topics

All topics →

The sizeof Operator in C++

Learn how the sizeof operator in C++ works: what it returns in bytes, how it handles arrays, pointers and structs, and common mistakes to avoid.

sizeof 6 min read

Bitwise XOR in C++

Learn how the bitwise XOR operator (^) in C++ works, with a truth table, code examples, and common uses such as toggling bits and swapping values.