Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pseudo code overview Create a new file main2D.c and code the main function below Input: Here we will use to define values as the dimensions

Pseudo code overview

Create a new file main2D.c and code the main function below

Input: Here we will use to define values as the dimensions of the array where DIM_1 is the size of the first dimension and DIM_2 is the size of the second dimension

Output: 0 if the operation was successful 1 if no memory was allocated Pseudo code + code #define DIM_1 10

#define DIM_2 5 int main(int argc, char **argv) { int **arr; // declare the arr variable as a two dimensional array int size; // will hold the size of the memory to be allocated int i; // allocate memory for the array of pointers to an int.

Namely, each element in the array will be of type int * // compute the value of size. Here you need to have an array that can hold 10 addresses. The size of each element is sizeof(int *), which gives the number of bytes to a pointer to an int size = ; arr = (int **) malloc(size); // note the type casting matches the arr declaration // add code to check if arr was properly allocated by checking whether it is NULL // allocate memory for each of the elements of arr for (i = 0 ; i < DIM_1; i++)

{ // allocate memory for each element of arr[i] // here the allocated memory is a one dimension of integers

// add code }

// using two nested for loop initialize each value of the two dimension array from 1 to DIM_1xDim_2 // using two nested for loop print one row at a time the array // pseudo code // set count to 1 // for i starting at 0 until DIM1 // for j starting at 0 until DIM2 // set arr[i][j] to count; // increment count by 1; // } //} return(0); }

Code the main function and test it. Using valgrind ensure that when the program terminates no memory is allocated.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago

Question

d. What language(s) did they speak?

Answered: 1 week ago

Question

e. What difficulties did they encounter?

Answered: 1 week ago