stdlib.h Flashcards
What is srand()?
Declaration:
void srand(unsigned int seed);
This function seeds the random number generator used by the function rand. Seeding srand with the same seed will cause rand to return the same sequence of pseudo-random numbers. If srand is not called, rand acts as if srand(1) has been called.
No value is returned.
What is calloc()?
Declaration:
void *calloc(size_t nitems, size_t size);
Allocates the requested memory and returns a pointer to it. The requested size is nitems each size bytes long (total memory requested is nitems*size). The space is initialized to all zero bits.
On success a pointer to the requested space is returned. On failure a null pointer is returned.
What is wcstombs()?
Declaration:
size_t wcstombs(char *str, const wchar_t *pwcs, size_t n);
Converts the codes stored in the array pwcs to multibyte characters and stores them in the string str. It copies at most n bytes to the string. If a multibyte character overflows the n constriction, then none of that multibyte character’s bytes are copied. Conversion stops when it reaches the null character or n bytes have been written to the string. The null character is stored in the string, but is not counted in the return value.
If an invalid code is reached, the value -1 is returned. Otherwise the number of bytes stored in the string is returned not including the terminating null character.
What is strtod()?
Declaration:
double strtod(const char *str, char **endptr);
The string pointed to by the argument str is converted to a floating-point number (type double). Any initial whitespace characters are skipped (space, tab, carriage return, new line, vertical tab, or formfeed). The number may consist of an optional sign, a string of digits with an optional decimal character, and an optional e or E followed by a optionally signed exponent. Conversion stops when the first unrecognized character is reached.
The argument endptr is a pointer to a pointer. The address of the character that stopped the scan is stored in the pointer that endptr points to.
On success the converted number is returned. If no conversion can be made, zero is returned. If the value is out of range of the type double, then HUGE_VAL is returned with the appropriate sign and ERANGE is stored in the variable errno. If the value is too small to be returned in the type double, then zero is returned and ERANGE is stored in the variable errno.
What is div()?
Declaration:
div_t div(int numer, int denom);
Divides numer (numerator) by denom (denominator). The result is stored in the structure div_t which has two members:
int qout;
int rem;
Where quot is the quotient and rem is the remainder. In the case of inexact division, quot is rounded down to the nearest integer. The value numer is equal to quot * denom + rem.
The value of the division is returned in the structure.
What is atol()?
Declaration:
long int atol(const char *str);
The string pointed to by the argument str is converted to a long integer (type long int). Any initial whitespace characters are skipped (space, tab, carriage return, new line, vertical tab, or formfeed). The number may consist of an optional sign and a string of digits. Conversion stops when the first unrecognized character is reached.
On success the converted number is returned. If the number cannot be converted, then 0 is returned.
What is rand()?
Declaration:
int rand(void);
Returns a pseudo-random number in the range of 0 to RAND_MAX.
The random number is returned.
What is atoi()?
Declaration:
int atoi(const char *str);
The string pointed to by the argument str is converted to an integer (type int). Any initial whitespace characters are skipped (space, tab, carriage return, new line, vertical tab, or formfeed). The number may consist of an optional sign and a string of digits. Conversion stops when the first unrecognized character is reached.
On success the converted number is returned. If the number cannot be converted, then 0 is returned.
What is mblen()?
Declaration:
int mblen(const char *str, size_t n);
Returns the length of a multibyte character pointed to by the argument str. At most n bytes will be examined.
If str is a null pointer, then zero is returned if multibyte characters are not state-dependent (shift state). Otherwise a nonzero value is returned if multibyte character are state-dependent.
If str is not null, then the number of bytes that are contained in the multibyte character pointed to by str are returned. Zero is returned if str points to a null character. A value of -1 is returned if str does not point to a valid multibyte character.
What is labs()?
Declaration:
long int labs(long int x);
Returns the absolute value of x. Not that in two’s compliment that the most maximum number cannot be represented as a positive number. The result in this case is undefined.
The absolute value is returned.
What is malloc()?
Declaration:
void *malloc(size_t size);
Allocates the requested memory and returns a pointer to it. The requested size is size bytes. The value of the space is indeterminate.
On success a pointer to the requested space is returned. On failure a null pointer is returned.
What is system()?
Declaration:
int system(const char *string);
The command specified by string is passed to the host environment to be executed by the command processor. A null pointer can be used to inquire whether or not the command processor exists.
If string is a null pointer and the command processor exists, then zero is returned. All other return values are implementation-defined.
What is bsearch()?
Declaration:
void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *));
Performs a binary search. The beginning of the array is pointed to by base. It searches for an element equal to that pointed to by key. The array is nitems long with each element in the array size bytes long.
The method of comparing is specified by the compar function. This function takes two arguments, the first is the key pointer and the second is the current element in the array being compared. This function must return less than zero if the compared value is less than the specified key. It must return zero if the compared value is equal to the specified key. It must return greater than zero if the compared value is greater than the specified key.
The array must be arranged so that elements that compare less than key are first, elements that equal key are next, and elements that are greater than key are last.
If a match is found, a pointer to this match is returned. Otherwise a null pointer is returned. If multiple matching keys are found, which key is returned is unspecified.
What is abort()?
Declaration:
void abort(void);
Causes an abnormal program termination. Raises the SIGABRT signal and an unsuccessful termination status is returned to the environment. Whether or not open streams are closed is implementation-defined.
No return is possible.
What is mbtowc()?
Declaration:
int mbtowc(whcar_t *pwc, const char *str, size_t n);
Examines the multibyte character pointed to by the argument str. The value is converted and stored in the argument pwc if pwc is not null. It scans at most n bytes.
If str is a null pointer, then zero is returned if multibyte characters are not state-dependent (shift state). Otherwise a nonzero value is returned if multibyte character are state-dependent.
If str is not null, then the number of bytes that are contained in the multibyte character pointed to by str are returned. Zero is returned if str points to a null character. A value of -1 is returned if str does not point to a valid multibyte character.