dynamic array

Below is a program which i wrote i want to make a dynamic array,my program is getting input.it should output the integers which i have entered but the program is displaying the addresses of the the input integers....
#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
int *p=NULL;
int n;
cout<<"Enter the size of the array";
cin>>n;
p=new int[n];
cout<<"Enter the elements of the array";
for(int i=0;i<n;i++)
cin>>*p++;
cout<<"Entered elements in the array are:";
for(int i=0;i<n;i++)
cout<<p++<<endl;
system("pause");
}
That's because you're printing the addresses:
cout<<p++<<endl;
Last edited on
Change your last cout statement to *p++. Without the *, you're using the memory location of p, or rather, what p points to. You did it right in the step above.
Ignored advice removed.
Last edited on
p++ means that you are printing the address of the values change that and it will work.
can any one paste correct version of my above code...?
Topic archived. No new replies allowed.