CS50 - Week 5
Malloc
Malloc allocates memory and returns the address of the first byte of that memory. It is on the onus of the caller to remember how much memory was requested.
int* count = malloc(sizeof(int)); // for an int
char* message = malloc(50 * sizeof(char)) // for a message that will be maximum 50 chars
Memory layout
Memory layout of a running program is comprised of different areas.
- Text - the area which holds the running program
- Initialised data
- Uninitialised data
- Heap
- Stack
- Environment variables