c++: The variables arr1 and arr2 have been declared as pointers to integers . An array of 10 elements has been allocated, its pointer assigned to arr1, and the elements initialized to some values . Allocate an array of 20 elements , assign its pointer to arr2, copy the 10 elements from arr1 to the first 10 elements of arr2, and initialize the remainder of the elements of arr2 to 0.

Respuesta :

Explanation:

Two variables named arr1 and arr2 have been declared as pointers to integers and arr1 is allocated 10 elements and initialized to some values.

Lets allocate 20 elements to arr2  

int *arr2 = new int[20];

Now using for loop we can copy 10 elements from arr1 to the first 10 elements of arr2

start from k = 0 and k < 10

for (int k = 0; k < 10; k++)

{

arr2[k] = arr1[k];

}

Again using for loop we can initialize the last 10 elements of arr2 to zero.

start from k = 10 and k < 20

for (int k = 10; k < 20; k++)

{

arr2[k] = 0;

}

ACCESS MORE