Question: Attached is a code excerpt using pointers and dynamic allocation of memory to your program (allocating memory to your program at run time). int *p;
Attached is a code excerpt using pointers and dynamic allocation of memory to your program (allocating memory to your program at run time).
int *p; int *q; int i;
p = new int[5]; p[0] = 5;
for (i = 1; i < 5; i++)
p[i] = p[i - 1] + 2 * i;
cout << "Array p: ";
for (i = 0; i < 5; i++)
cout << p[i] << " ";
cout << endl; // 1 **********************************************
q = new int[5];
for (i = 0; i < 5; i++)
q[i] = p[4 - i];
cout << "Array q: ";
for (i = 0; i < 5; i++)
cout << q[i] << " ";
cout << endl; // 2 ******************************************************
Write a program utilizing this code excerpt.
What will be the output after comment 1?
What will be the output after comment 2?
c++ and please please make it correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
