CSC209H5 Chapter Notes - Chapter 3: Memory Leak, C Dynamic Memory Allocation, Memory Address
Document Summary
Csc209h5s - software programming and tools (winter 2018) When you try the run the above function, you will get a warning message telling us we are trying to return the memory address of the variable in the stack. However, if you run the program, it still works. You will notice the *pt will return 999. Variable i is declared as local variable, it gets removed when the function is completed, leaving a space available for junk. Junk then takes the memory address of the variable i which is why it outputs 999. Heap - memory available until the programmer tells the program to clear it. void *malloc(size_t size); Size parameter indicates how many bytes of memory should be allocated. size_t is the type (an unsigned int). The return type is void * - doesn"t need to know how the memory allocated is stored.