🔧 C Language — Headers, Functions & Code Examples

Complete reference for the C Standard Library and POSIX headers — designed for students and developers. Click any header to see all its functions, signatures, and a ready-to-compile example.
Part of The Direct Path to Linux Ubuntu — free for all students.

13Headers
176+Functions
5Quick Examples
GCCCompiler
C99/C11Standards
HTTPSPort 443
📥 Input / Output 🔢 Math & Numbers 🔤 Strings & Memory ⚙️ General Utilities 🕐 Time & Date ❌ Errors & Signals 🐧 POSIX / Linux

📥 Input / Output

📄 <stdio.h>Standard Input / Output

🔢 Math & Numbers

📐 <math.h>Mathematical Functions
🔢 <stdint.h>Fixed-Width Integer Types (C99+)
📏 <limits.h>Integer Type Limits
✅ <stdbool.h>Boolean Type (C99+)

🔤 Strings & Memory

🔤 <string.h>String & Memory Operations
🔡 <ctype.h>Character Classification & Conversion

⚙️ General Utilities

⚙️ <stdlib.h>General Utilities — Memory, Conversion, Process

🕐 Time & Date

🕐 <time.h>Date & Time Functions

❌ Errors & Signals

❌ <errno.h>Error Number Definitions
📡 <signal.h>Signal Handling
🛑 <assert.h>Diagnostic Assertions

🐧 POSIX / Linux

🐧 <unistd.h>POSIX API — Process, Files, I/O (Linux/macOS only)

⚡ Quick Copy-Paste Examples

Ready-to-compile C programs. Save to a .c file, then compile with the command shown in the comment.

Hello, World!

The classic starting point — output to stdout.

#include <stdio.h>
int main(void) {
    printf("Hello, World!\n");
    return 0;
}
/* gcc -Wall -o hello hello.c && ./hello */

Read User Input

Read a name and age with scanf.

#include <stdio.h>
int main(void) {
    char name[64]; int age;
    printf("Name: "); scanf("%63s", name);
    printf("Age:  "); scanf("%d",   &age);
    printf("Hi %s, you are %d years old.\n", name, age);
    return 0;
}
/* gcc -Wall -o input input.c && ./input */

Simple Calculator

Add, subtract, multiply, divide two numbers.

#include <stdio.h>
int main(void) {
    double a, b;
    printf("Enter two numbers: ");
    scanf("%lf %lf", &a, &b);
    printf("%.2f + %.2f = %.2f\n", a, b, a + b);
    printf("%.2f - %.2f = %.2f\n", a, b, a - b);
    printf("%.2f * %.2f = %.2f\n", a, b, a * b);
    if (b != 0) printf("%.2f / %.2f = %.2f\n", a, b, a / b);
    else        printf("Division by zero!\n");
    return 0;
}
/* gcc -Wall -o calc calc.c && ./calc */

Dynamic Array with malloc

Allocate an int array at runtime and sort it.

#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; }
int main(void) {
    int n; printf("How many integers? "); scanf("%d", &n);
    int *arr = malloc(n * sizeof(int));
    if (!arr) { perror("malloc"); return 1; }
    for (int i = 0; i < n; i++) arr[i] = rand() % 100;
    qsort(arr, n, sizeof(int), cmp);
    for (int i = 0; i < n; i++) printf("arr[%d] = %d\n", i, arr[i]);
    free(arr);
    return 0;
}
/* gcc -Wall -o dyn dyn.c && ./dyn */

Linked List

Build and traverse a singly linked list.

#include <stdio.h>
#include <stdlib.h>
typedef struct Node { int val; struct Node *next; } Node;
Node *push(Node *head, int val) {
    Node *n = malloc(sizeof(Node));
    n->val = val; n->next = head; return n;
}
void print_list(Node *n) {
    for (; n; n = n->next) printf("%d -> ", n->val);
    printf("NULL\n");
}
void free_list(Node *n) {
    while (n) { Node *t = n->next; free(n); n = t; }
}
int main(void) {
    Node *list = NULL;
    for (int i = 1; i <= 5; i++) list = push(list, i * 10);
    print_list(list);
    free_list(list);
    return 0;
}
/* gcc -Wall -o list list.c && ./list */