Question: 1. About Pointers and Dynamic Memory Allocation Finish this code.. #include #include using namespace std; int main() { string * namesPtr; // pointer namesPtr will
1. About Pointers and Dynamic Memory Allocation
Finish this code..
#include
#include
using namespace std;
int main()
{
string * namesPtr; // pointer namesPtr will hold the starting address of a dynamic array
// of string's where we will hold a name in each array element
int size;
cout << "How many names do you like to store: ";
cin >> size;
// dynamically creating an array of size amount of strings
// The starting address of the dynamic array is stored in pointer namesPtr
namesPtr = new string[size];
// a.Write C++ code that inputs data(say names of your family members) into
// the dynamic array in part a above from the keyboard.
// hint: you need to write a loop
// b.Write C++ code that output data from the dynamic array to in part b above to the screen.
// hint:you need to write a loop
// c.Write a C++ code to de-allocates (frees) the memory space allocated
// for the dynamic array created in part a above.
system("pause");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
