/* COMP 2401/2001 Day 13 - Feb 25th 2013 Memory Leak Example 1 */ #include #include #include #define SIZE 10 // forward declaration of function print() void print(int x[], int size); int main(int argc, char* argv[]){ srand((unsigned)time(NULL)); // allocate memory on the heap for SIZE integers int* x = (int*) malloc( SIZE * sizeof(int) ); printf("x points to memory location %p (%lu) in the heap\n", x, (unsigned long)x); // populte the array with random values srand((unsigned)time(NULL)); for(int i = 0; i < SIZE; i += 1){ x[i] = rand()%100; } // print out the contents of the array // print(x,SIZE); // have x point to somowhere else memory // (x is now pointing to the stack since y is local to main) int y = 17; x = &y; printf("x points to memory location %p (%lu) in the stack (activation record for main)\n", x, (unsigned long)x); // print(x,SIZE); } void print(int x[], int size){ for(int i=0; i