09 Flashcards
What is the function prototype for realloc?
void* realloc(void*, int size);
What does realloc do?
Realloc changes the size of a buffer which was previously malloced.
Does realloc always move the data?
No. If the new size is smaller than the old, the data may just be truncated. Also, if there is enough memory and the size is bigger than the old size, then it may just extend the allocated space.
What does realloc return on failure?
NULL
What does realloc return on success?
A pointer to the newly reallocated block of data.
What is the function prototype for memcpy?
void* memcpy(void *dst, void *src, size_t n);
What does the function memcpy do?
It copies n bytes of data from a source pointer to a destination pointer.
What is the function prototype for memmove()
void* memmove(void *dst, void *src, size_t n);
What is the difference between memcpy and memmove?
Memmove is identical except it promises to work regardless of how the memory blocks overlap. memcpy might not work correctly in this case.
How does memcpy work with structs?
It doesn’t. Don’t do it.
How many bytes need to be malloced to store the following string:
“abcdefg”?
8.
Always remember to leave an extra byte for the null terminator ‘\0’.
Which of the following constants does not exist?
INT_MIN, INT_MAX, UINT_MAX, UINT_MIN
UINT_MIN.
There is no need for this as it will always be 0.
What values does rand() return values between?
0 and RAND_MAX.
RAND_MAX is always at least 32767.
What method is used to seed the random numbers?
srand()