Language Reference2026-08-142 min read
Comprehensive guide to standard C library header functions across stdio.h, stdlib.h, string.h, and math.h with syntax and tested code.
Overview of the ISO C Standard Library
The C Standard Library (libc) provides standardized utility functions, macro definitions, and data types built into every compliant ISO C environment.
1. <stdio.h> — Input & Output Functions
Header for console streams, file operations, and formatted input/output:
int printf(const char *format, ...): Print formatted text to standard output.int scanf(const char *format, ...): Read formatted input from standard input.FILE *fopen(const char *path, const char *mode): Open a file stream.int fclose(FILE *stream): Close an open file stream.char *fgets(char *s, int size, FILE *stream): Read a line safely from a stream.
c (ISO Standard)#include <stdio.h> int main() { printf("Standard output formatted string: %d\n", 42); return 0; }
2. <stdlib.h> — Dynamic Memory & Utilities
Header for heap memory management, conversions, and process lifecycle:
void *malloc(size_t size): Allocate uninitialized heap memory.void *calloc(size_t nmemb, size_t size): Allocate zero-initialized memory.void free(void *ptr): Release dynamically allocated memory back to system.int atoi(const char *nptr): Convert string to integer.void exit(int status): Terminate calling process immediately.
c (ISO Standard)#include <stdio.h> #include <stdlib.h> int main() { int *buffer = (int *)malloc(2 * sizeof(int)); if (buffer != NULL) { buffer[0] = 100; buffer[1] = 200; printf("Heap value #1: %d, #2: %d\n", buffer[0], buffer[1]); free(buffer); } return 0; }
3. <string.h> — String & Memory Manipulation
size_t strlen(const char *s): Returns length of string excluding null terminator.char *strcpy(char *dest, const char *src): Copy string into destination buffer.int strcmp(const char *s1, const char *s2): Lexicographical string comparison.void *memset(void *s, int c, size_t n): Fill memory block with a constant byte.
4. <math.h> — Common Mathematical Routines
double sqrt(double x): Calculate square root.double pow(double base, double exp): Calculate power exponentiation.double fabs(double x): Absolute value of a floating-point number.
Related Guides & References
- Look up formatted placeholder tokens in C Format Specifiers Reference.
- Review reserved language tokens in C Reserved Keywords Reference.
- Test standard library functions interactively in the Online C Compiler.