Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please colored your code that you will add 2darray.c code : #include #include /* free memory for 2D array */ void free2Darray(int **a, int height)

please colored your code that you will add

image text in transcribed

2darray.c code :

#include #include

/* free memory for 2D array */ void free2Darray(int **a, int height) { int i = 0; for(i = 0; i

/* make 2D array and initialize each location with its row number */ int** make2Darray(int width, int height) { int **a = NULL; int i = 0; int j = 0;

if(width

return a; }

/* print contents of 2D array */ void print2Darray(int **a, int width, int height) { int i, j; if (a == NULL) { printf("null array "); return; } for(i = 0; i

/* create a 2d array of ints and prints it to the screen */ int main() { int width, height; int **array = NULL; printf("Enter the width: "); if(scanf("%d", &width) != 1) { printf("Aborting. "); return EXIT_FAILURE; } printf("Enter the height: "); if(scanf("%d", &height) != 1) { printf("Aborting. "); return EXIT_FAILURE; } printf("width: %d ", width); printf("height: %d ", height); array = make2Darray(width, height); if(array != NULL) { print2Darray(array, width, height); /* free memory */ free2Darray(array, height); } array = NULL; return EXIT_SUCCESS; }

The main function in 2darray.c: prompts the user for the height and width of the 2D array calls the make2Darray function to create a 2D array of ints with that size and returns a pointer to the dynamically-allocated array prints the values in the array to the screen using print2Darray As implemented, the make2Darray function allocates memory to store the 2D array. Inspect this function to see how the allocation and freeing of memory works. Why is the type of a (int **)? Why is the type of a[i] (int ? As implemented, the free2Darray function frees the memory for the 2D array. Inspect this function to see how the array is "freed": first each row is "freed" and then the array is "freed" 2. Compile and run the program. 3. Add code to the function make2Darray to do the following: .Initialize each element in the 2D array with its row number. For example, a height 4 and width 3 array would have the values: 2 3 2 3 2 Checkpoint 3 125 pointsl:Show your answers above and your modified 2darray.c program (take a screenshot or copylpaste text to the lab handout). Demonstrate its execution

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5. Explain how to install a performance management program.

Answered: 1 week ago

Question

=+Understand the fi eld of comparative IHRM.

Answered: 1 week ago