Rand, Realloc, Rand realloc – Zilog ZUSBOPTS User Manual
Page 463: Example, Synopsis, Returns

UM017105-0511
Standard Functions
Zilog Developer Studio II – ZNEO™
User Manual
435
Example
int lst[]={5,8,2,9};
int compare (const void * x, const void * y);
qsort (lst, sizeof(int), 4, compare);
int compare (const void * x, const void * y)
{
int a = *(int *) x;
int b = *(int *) y;
if (a < b) return -1;
if (a == b)return 0;
return 1;
}
The
compare
function prototype is, as shown in the preceding example:
int compare (const void * x, const void * y);
rand
Computes a sequence of pseudorandom integers in the range 0 to RAND_MAX.
Synopsis
#include
int rand(void);
Returns
A pseudorandom integer.
Example
int i;
srand(1001);
i=rand();
realloc
Changes the size of the object pointed to by ptr to the size specified by size. The contents
of the object are unchanged up to the lesser of the new and old sizes. If ptr is a null pointer,
the
realloc
function behaves in a similar fashion to the
malloc
function for the speci-
fied size. Otherwise, if ptr does not match a pointer earlier returned by the
calloc
,
mal-
loc
, or
realloc
function, or if the space has been deallocated by a call to the
free
or
realloc
function, the behavior is undefined. If the space cannot be allocated, the
real-
loc
function returns a null pointer and the object pointed to by ptr is unchanged. If size is