07 - 08 Flashcards
Which types of variables are automatically zeroed in C?
Static function variables.
Static and non-static variables.
Where are automatic function variables stored?
The stack.
What type does malloc return?
A void pointer. It can store any sort of data.
What happens if you try to write to memory that has already been freed?
Undefined behaviour
What happens when malloc fails to allocate sufficient memory?
It returns NULL.
Is malloced data automatically zeroed?
No.
What library contains malloc and free?
stdlib.h
For a struct containing values which are pointers, why is it recommended to make a ‘deep copy’ method?
The struct values will contain pointers to the same data, and not its own copy of the data.
What is the function prototype for calloc?
void* calloc(size_t num, size_t size);
What does calloc do?
It takes a size and a number, and mallocs (size * number) bytes. It then zeroes all of the data.
What is the type ‘size_t’?
An unsigned integer type big enough to fit a pointer in.
What library holds definition for ‘size_t’ and ‘ptrdiff_t’?
stddef.h