#include<stdio.h>
#include<iostream.h>
#include<conio.h>

void main()
{
int size=5,i,j;
clrscr();
//cout<<"Enter the length of array : ";
// cin>>size;

int *array = new int[size];

cout<<"Enter elements "<<endl;
for(i=0;i<size;i++)
cin>>array[i];

for(i=0;i<size-1;i++)
{
for(j=i+1;j<size;j++)
{
if(array[i]>array[j])
{
int temp;
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
cout<<"Sorted array"<<"\n";
for(i=0;i<size;i++)
cout<<array[i]<<' ';

for(i=array[i];i>0;i--)
{
delete[] array;
cout<<"\n"<<array[i]<<"\n";
}

getch();
}

after deleteing I want to show the array contents........ This is my problem...
Please help me............... please correct this problem....

Edited 5 Years Ago by Nick Evan: Added [CODE] tags. Try adding them yourself next time.

after deleteing I want to show the array contents........

That doesn't make one bit of sense. Also, why are you trying to delete the array multiple times, delete [] array; takes care of it.

after deleteing I want to show the array contents

As Jonsca said, that is the problem. Show the array contents, then delete the array.

As Jonsca said,

There should be a button to insert that phrase in the advanced editor.

Also, @OP, main is always int, never void, according to the standard. Even if your compiler takes it, it shouldn't.

As Jonsca said, that is the problem. Show the array contents, then delete the array.

In array should show any garbage values. But it is not showing garbage value, for first 2 elements shows garbage value and rest are showing array contents............

Deleting the array does not write garbage values into it. The memory is available for other use, but will only change its contents when something writes over that memory. That could happen at any time, without your knowledge, so do not try to read a value from memory after you have deleted it.

This question has already been answered. Start a new discussion instead.