Skip to content

Stdlib.h

1. String Conversion

Functions to convert strings into numerical types.

Function Description Example
int 
 atoi(const char *str)
Convert string to integer atoi("1024") 
//1024
double 
 atof(const char *str)
Convert string to double atof("3.14") 
//3.14
long 
 strtol(const char str, char *end, int base)
Convert string to long integer with base selection strtol("1A", NULL, 16) 
// 26

2. Memory Management

Functions for dynamic memory allocation and deallocation.

Function Description Example
void* 
 malloc(size_t size)
Allocate a block of uninitialized memory int p = malloc(sizeof(int)5);
void* 
 calloc(size_t nitems, size_t size)
Allocate memory and initialize bytes to zero int *p = calloc(5, sizeof(int));
void 
 realloc(void
ptr, size_t size)
Resize a previously allocated memory block p = realloc(p, sizeof(int)*10);
void 
 free(void *ptr)
Deallocate/Free memory free(p);

3. Random Numbers & Arithmetic

Basic integer math and random number generation.

Function Description Example
int 
 abs(int x)
Absolute value of an integer abs(-10) 
 //10
void 
 srand(unsigned int seed)
Seed the random number generator srand(time(0));
int 
 rand(void)
Generate a pseudo-random integer rand() % 100 
// 42

4. Sorting & System Control

Process control and algorithm utilities.

Function Description Example
void 
 exit(int status)
Terminate the program normally exit(0);
int 
 system(const char *command)
Execute a shell command system("ls -l");
void 
 qsort(void base, size_t n, size_t size, int (cmp)(...))
Sort an array (Quicksort) qsort(arr, 5, sizeof(int), cmp);