Wednesday 25 July 2012

cstdlib Library

<cstdlib>

Miscellaneous functions. s is type char*, n is int
atoi(s); atol(s); atof(s);// Convert char* s to int, long, double e.g. atof("3.5")
abs(x); labs(x); // Absolute value of numeric x as int, long
rand(); // Pseudo-random int from 0 to RAND_MAX (at least 32767)
srand(n); // Initialize rand(), e.g. srand(time(0));
system(s); // Execute OS command s, e.g. system("ls");
getenv(s); // Environment variable or 0 as char*, e.g. getenv("PATH");
exit(n); // Kill program, return status n, e.g. exit(0);
void* p = malloc(n); // Allocate n bytes or 0 if out of memory. Obsolete, use new.
p = calloc(n, 1); // Allocate and set to 0 or return NULL. Obsolete.
p = realloc(p, n); // Enlarge to n bytes or return NULL. Obsolete.
free(p); // Free memory. Obsolete: use delete

No comments:

Post a Comment