In the following code both myList and yourList are dynamic arrays of the same size. The code initializes the array myList to certain values. The value in each element of yourList should be twice the value in the corresponding element in myList. However, the output of this code would show that is not the case. Provide the correct code to accomplish the desired results. int *myList;int *yourList;myList = new int[5];myList[0] = 8;for (int i = 1; i < 5; i++)myList[i] = i * myList[i - 1];yourList = myList;for (int i = 0; i < 5; i++)yourList[i] = 2 * myList[i];
In the following code both myList and yourList are dynamic arrays of the same size. The code initializes the array myList to certain values. The value in each element of yourList should be twice the value in the corresponding element in myList. However, the output of this code would show that is not the case. Provide the correct code to accomplish the desired results. int *myList;int *yourList;myList = new int[5];myList[0] = 8;for (int i = 1; i < 5; i++)myList[i] = i * myList[i - 1];yourList = myList;for (int i = 0; i < 5; i++)yourList[i] = 2 * myList[i];
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 29SA
Related questions
Question
In the following code both myList and yourList are dynamic arrays of the same size. The code initializes the array myList to certain values. The value in each element of yourList should be twice the value in the corresponding element in myList. However, the output of this code would show that is not the case. Provide the correct code to accomplish the desired results.
int *myList;
int *yourList;
myList = new int[5];
myList[0] = 8;
for (int i = 1; i < 5; i++)
myList[i] = i * myList[i - 1];
yourList = myList;
for (int i = 0; i < 5; i++)
yourList[i] = 2 * myList[i];
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning