Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Give me an example of deep copy and shallow copy of the structure. (C-Language) The structure is made by the following function: struct Double_Array {

Give me an example of deep copy and shallow copy of the structure. (C-Language)

The structure is made by the following function:

struct Double_Array {

double **array;

int rowsize;

int colsize;

};

struct Double_Array *double_array(int row, int col) {

struct Double_Array *ptr = malloc(sizeof(struct Double_Array));

ptr->array = malloc(sizeof(double *) * row);

for (int i = 0; i < row; i++) {

ptr->array[i] = malloc(sizeof(double) * col);

}

ptr->rowsize = row;

ptr->colsize = col;

return ptr;

}

void randomize_array(struct Double_Array *ptr, double row, double col) {

for (int i = 0; i < row; i++) {

for (int j = 0; j < col; j++) {

ptr->array[i][j] = rand_double(0.0, 10.0);

}

}

}

int main(){

int row = 6;

int column = 9;

struct Double_Array *a1;

a1 = double_array(row, column);

randomize_array(a1, row, column);

}

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

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions