-
Notifications
You must be signed in to change notification settings - Fork 2
stdlib.h
hengxin edited this page Nov 24, 2017
·
1 revision
stdlib.h: C Standard General Utilities Library
This header defines several general purpose functions, including dynamic memory management, random number generation, communication with the environment, integer arithmetics, searching, sorting and converting.
void qsort (void* base, size_t num, size_t size, int (*compar)(const void*,const void*));
Sorts the num elements of the array pointed to by base, each element size bytes long,
using the compar function to determine the order.
An example of compar function:
int compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
#include <stdlib.h>
#include <time.h>
srand(time(NULL));
int i = rand() % 10; // i \in [0, 9]