/*****************************************************************************
 * 'main' illustrates dynamic allocation of an array. 
 * **************************************************************************/
#include<iostream>
#include<iomanip>
#include<cstddef>// This gives us size_t, a type to hold the size of an array.
#include<cstdlib>

using std::cin; using std::cout;
using std::endl; 

/* Replace the dynamically allocated array p with
 * 'size' copies of x, freeing the old memory. 
 */
int* value_fill(int*& p, size_t size, int x)
{
	delete[] p;
       	p=new int[size];
	for(int i=0; i!=size; i++)
		p[i]=x;
		
	return p;
}


	

int main()
{
	size_t repeats;
	int value;
	int* p=new int[3];//value initialization
	p[0]=5;
	cout<<"The current contents of p: "<<endl;
	for(size_t i=0; i!=3; i++)
		cout<<p[i]<<" ";
	
	cout<<endl<<"Please enter the size of the array "
		<<"and the value to load: ";
	cin>>repeats>>value;
	value_fill(p,repeats,value);
	for(size_t i=0; i!=repeats; i++)
		cout<<p[i]<<" ";
	

	return 0;
}

	
