Description
1 Requirements
This lab is intended to test your ability to do pointer arithmetic and cast pointers. You will be provided
with a main file in your starter code, but any testing code you produce will not be graded in this lab.
1.1 getArrayMax
int getArrayMax ( double * array ) ;
Info: This function takes an array of type double, and retrieves the array max which is stored in the
extraBytes at the end of the array in the form of an int. You must correctly cast and offset the array
pointer to access the extraBytes space without reading the last array element or reading past the end
of the allocated block of memory.
i
1.2 findArrayMax
void findArrayMax ( double * array ) ;
Info: This function takes an array of type double, and finds the array max. The result of this function
should be stored in the extraBytes at the end of the array in the form of an int. You must correctly cast
and offset the array pointer to access the extraBytes space without writing over the last array element
or reading past the end of the allocated block of memory.
i
1.3 createArray
void * createArray ( int size , size_t elemSize , size_t extraBytes ) ;
Info: This function will create a dynamically allocated array whose size is defined by the provided
parameters. The function must allocate enough space to hold the elements specified, as well as
enough space to hold the integer size before the array and the extraBytes specified.
i
1.4 getArraySize
int getArraySize ( void * array ) ;
Info: This function takes an array allocated using the createArray function and returns the integer
size stored before the array.
i
1
1.5 freeArray
void freeArray ( void * array ) ;
Info: This function takes an array allocated using the createArray function and frees the array memory.
i
2 Notice
Grading:
1. Write required getArrayMax function
* 4 points
2. Write required findArrayMax function
* 6 points
3. Write required create array function
* 4 points
4. Write required get array size function
* 2 points
5. Write required free array function
* 2 points
!
Notice:
1. All of your lab submissions must compile under GCC using the −W all and −W error flags to be
considered for a grade.
2. You are expected to provide proper documentation in every lab submission, in the form of
code comments. For an example of proper lab documentation and a clear description of our
expectations, see the lab policy document.