I tried many ways i searched on the internet but none helped may be cause i cant ask the right question so please help with explaining the current problem and any problems that i might face close to this thx in advance
#include <iostream>
using namespace std;
int main()
{
int i,n;
//1 - Automatic array allocation (The size of array is known before run - constant) ------------
int A[10];
cout<< "\nValue of variable A=" << A<< " ('Roughly Speaking' Array name is a constant pointer )";
for(i=0; i<10; i++)
A[i]=2*i;
cout<<"\nValues of the array A: ";
for(i=0; i<10; i++)
cout<<A[i]<<" ";
//Using pointers to access array elements
int* P=A;
P[0]=99;
P[9]=888;
cout<<"\n\nValues of the array A: ";
for(i=0; i<10; i++)
cout<<A[i]<<" ";
cout<<"\n\nEnter the number of array elements:";
cin>>n;
//The new opertor. (dynamic allocation)
P=new int[n];
for(i=0; i<n; i++)
P[i]=5*i;
cout<<"\n\nValues of the array pointed to by pointer P:\n";
for(i=0; i<n; i++)
cout<<P[i]<<" ";
//To free the array memory. notice the square brackets
delete [] P;
//P=NULL; //Note: good to set P = NULL after deletion
cout<<"\n\nValues of the array pointed by pointer P (after delete):\n";
for(i=0; i<n; i++)
cout<<P[i]<<" ";
cout<<"\n\nDeleting pointer P does not mean you can not use it again";
P = A+4;
cout<<"\nP[0]="<<P[0]<<", A[4]="<<A[4];
cout<<"\nP[5]="<<P[5]<<", A[9]="<<A[9];
A[3] = 6;
//for(int j=0;j<10;j++)
//{
// delete P[j];
//}
delete [] P; //--------------here the problem
cout<<endl;
getchar();
return 0;
}
....................................................... ......................................... .................................. .........................