In a C tutorial, almost every useful program leans on the C standard library—headers such as <stdio.h>, <string.h>, and <stdlib.h>. A header declares functions, types, and macros; the library implementation supplies the machine code. You write #include <stdio.h> so the compiler knows printf exists; the linker attaches the real printf from the C runtime.
Header vs library
The .h file is the contract. The linked library (libc, and often libm for math) is the implementation. Missing an include is a compile problem; missing -lm for sqrt is a link problem.
This page is the C library lesson: how #include works, which header fits which job, and how headers work together. Each name in the headers index opens a focused guide (19 tutorials) with syntax, examples, and FAQs—for example stdio.h.
Include only what you use.
If a .c file needs printf and strlen, include both <stdio.h> and <string.h>. Do not rely on one header to pull in another unless the standard guarantees it.
Headers declare; libraries define.
A missing #include fails at compile time. A missing -lm for math fails at link time—different stage, different fix.
Angle brackets vs quotes.
#include <stdio.h> searches system paths. #include "my.h" is for your project headers. Use brackets for the standard library.
Syntax
C Syntax
Put standard includes at the top of the source file, before your code:
List the jobs your program needs (print, read, copy a string, allocate memory, compute a root).
Map each job to a header with Choose a Header by Job above.
Add #include <…> lines at the top of the .c file—only what you use.
Compile with -std=c11; add -lm last if you call math.h functions.
Check return values (malloc, fopen) and free what you allocate.
Open a single-header page from the searchable index when you need a full walkthrough.
Try it
Live Preview
Toggle the jobs you need—the preview shows which standard headers a C tutorial program would typically include.
Program needs
Suggested includes
#include <stdio.h> #include <string.h>
Compile: gcc main.c -std=c11 -o main
Code
C Examples
Five starter patterns that combine the headers you meet first in a C tutorial. Compile with gcc file.c -std=c11 -o out.
Example 1 — Hello with stdio.h
The smallest useful program uses printf from <stdio.h>.
C
#include <stdio.h>
int main(void) {
printf("Hello from the C standard library!\n");
printf("stdio.h provides printf, scanf, and file I/O.\n");
return 0;
}
Most library bugs in C tutorials are missing includes, missing -lm, or unsafe string/memory use.
inc
Implicit declaration warnings
Calling printf without #include <stdio.h> is undefined in modern C. Include the header.
-lm
undefined reference to sqrt
Including math.h is not enough on GCC/Clang—add -lm at the end of the link line.
buf
strcat / strcpy overflows
Destination buffers must be large enough. Prefer bounded copies when available, and track capacity.
NULL
Unchecked malloc / fopen
Always test for NULL before using the pointer or FILE*.
ctype
Passing char to isdigit
Cast to (unsigned char) (or use EOF) so values above 127 are safe.
hdr
Assuming transitive includes
If you use a name from string.h, include string.h—even if another header happened to include it on your machine.
Platform
Platform Support
The headers on this page are part of standard C. Linking details differ mainly for math.
Toolchain
Support
Notes
GCC (Linux / MinGW)
Full
libc automatic; math usually needs -lm
Clang (macOS / Linux)
Full
Same pattern as GCC for math.h
MSVC
Full
Math often links automatically
Freestanding / embedded
Varies
May lack full hosted library; check vendor docs
Hosted C environments provide stdio, stdlib, and string without extra flags. Wide-character and locale headers are standard but less common in early tutorials—learn them after the core three.
Remember
Key Takeaways
Headers declare; the linked library provides the code.
One line: The C standard library is #include + link—learn stdio, string, and stdlib first, then use the headers index for the rest.
Frequently Asked Questions
The C standard library is a set of headers (stdio.h, stdlib.h, string.h, and others) that declare functions, types, and macros for I/O, memory, strings, math, time, and more. You #include the headers you need; the linker connects your program to the library implementation.
Use angle brackets: #include <stdio.h>. Angle brackets tell the compiler to search system include paths. Quotes (#include "my.h") are for your own project headers. Include only the headers each .c file uses directly.
Start with stdio.h (printf, scanf), string.h (strlen, strcmp), and stdlib.h (malloc, exit). Add ctype.h for character tests, math.h for calculations (often with -lm), and errno.h when system calls fail.
Usually no for stdio, stdlib, and string. On GCC and Clang, math.h functions often require -lm at the end: gcc program.c -std=c11 -o program -lm. Windows MSVC typically links math automatically.
The .h header declares names (prototypes, macros, types). The compiled library provides the actual machine code. Including stdio.h lets the compiler check printf; the linker pulls in printf's implementation.
Practice the examples on this page, then open stdio.h, string.h, and stdlib.h. Use the headers index below when you need a specific API. Related tracks: C Strings and C Math.