Table of Contents

C standard library

C standard library is the core set of headers and functions always linked into C programs, providing essential utilities like I/O (<stdio.h>), memory management (<stdlib.h>), string handling (<string.h>), and math operations (<math.h>). Headers declare functions and constants; the library implementation lives in libc.so (dynamic) or libc.a (static).

Modern C lacks advanced data structures (no maps, vectors, or trees), async/threading, and networking—you must implement these yourself or use external libraries.

Example

This example demonstrates basic C standard library usage with I/O and memory allocation.

// compile: gcc -o stdlib stdlib.c
// run: ./stdlib
// description: use standard library for I/O, memory, and string operations
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main() {
    char *buffer = malloc(50);
    if (!buffer) {
        fprintf(stderr, "Memory allocation failed\n");
        return EXIT_FAILURE;
    }
 
    strcpy(buffer, "Hello from stdlib");
    printf("%s\n", buffer);
 
    free(buffer);
    return EXIT_SUCCESS;
}