% cd ~/cs21/ % mkdir week9 % cd week9 % cp ~newhall/public/cs21/week9/* . % ls
You will implement a function that returns a dynamically allocated array of int values initialized with values entered by the user. The function will read in a value for the number of ints to be read in (the size of the array), dynamically allocate an array of that size, and then fill it with values entered by the user. The function will return the dynamically allocated array, and will "return" the size of the array using pass-by-reference.
% valgrind ./a.out # or to get more information about memory leaks: % valgrind --leak-check=yes --show-reachable=yes ./a.outYou also can give valgrind a command line option to write its output to a file that you can view using emacs or vi:
% valgrind --log-file=memerrors ./a.out
Valgrind is a useful tool for debugging memory access errors like stepping beyond the bounds of an array, memory leaks, and so on. Unfortuanetly it only works for checking dynamically allocated memory, so we have not used it up until now. Memory access errors are often the most difficult ones to find, so valgrind can save you many hours of frustrating debugging time by pointing you directly to the error.
Some more information on using valgrind is available here.