Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Two-dimensional dynamic arrays The concept of dynamic array that you implemented in Problem 3 above can be extended to a multi-dimensional array. In this

image text in transcribed
image text in transcribed
image text in transcribed
4. Two-dimensional dynamic arrays The concept of dynamic array that you implemented in Problem 3 above can be extended to a multi-dimensional array. In this program, you will implement a dynamic 2-D array. Declaration Just like a one dimensional array name is a pointer, a 2-D array name is also a pointer, but it is a different type of pointer. For example, you declare an ordinary pointer as int "p: A double-referenced pointer will be declared as int *p 2D Dynamic Memory Allocation: You allocate memory to a 2D array in a similar way you do to a 1D array. For example, if we want to allocate memory to pointer p: p-new intIsizel: where p is the name of the pointer, int is the data type, size is the size of the array. Similarly, if we want to allocate memory to pointer p 2D: P 2D-new int [row_size] where p 2D is the name of the pointer, int* is the data type, row size is the size of the 2D array. A 2D array is an array with 1D arrays as members, and each row of the 2D array is a member 1D array. In a 2D array, the row size is related to the size of the 2D array (i.e. how many 1D arrays are in that 2D array) while the column size is associated with the type of the 2D array (i.e. how big the individual 1D arrays are). Here we don't know column size at compile time and hence we use int* Now we need to allocate memory to each row of the 2D array. For this we can use a loop as: 5 (int //Prompt user for the value of column_size p 2D[i]-new int [column_size] for =0;rowsize: ++i) - Dereferencing: To extract the values from a 2D array, you have to deference twice-hence it can also be

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

What is the difference between an SF2andan SF3 forecast?

Answered: 1 week ago