Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Prelab: Week of February 17th This prelab involves the implementation of functions for dynamically creating and using 2D arrays, which are sometimes called tables or
Prelab: Week of February 17th This prelab involves the implementation of functions for dynamically creating and using 2D arrays, which are sometimes called tables or matrices depending on the application. The first function creates a table with size determined respectively by parameters for the number of rows, the number of columns, and the element size: array = createTable (numRows, numCols, elemSize); The first thing our function must do is allocate a 1D array of pointers to the rows, so row[i] is a pointer to row i, which is a 1D array. Then we need to allocate the rows, each of which is a 1D array with length given by numCols with element size given by elemSize. In other words, we need to have a loop to allocate each row as: row[i]= malloc (numCols elemSize). This 1D array contains pointers to 1D arrays representing the rows of a 2D array, TITIIIIIIIIIIII + IIIIIIII +IIIIIIIIIIIII TOIIIIIIIIIIIIIII E | | | | | | | | | | | | As was the case in the previous prelab, inside of createTable we don't know what data type the user is working with: we just know the size of the elements. So we could declare the array of row pointers as void **row, or equivalently as void *row[], whichever we prefer. Now, for example, a user can create a 100x100 2D array of floats and initialize the elements to zero as follows: float **p; p = createTable (100, 100, sizeof(float)); for (i=0, i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started