Delete Array Problem

I have problem with freeing the memory from the un-using data, please help me! thank you :))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  void main()
{
int Data[] = {0 ,1, 1, 0, 0, 0,0 ,0 ,0 ,1 ,1 ,0,0 ,1 ,0 ,0 ,1 ,0,0 ,0 ,0 ,0 ,1 ,1,0, 1, 0, 0, 0, 1,0, 0, 0, 0, 0, 0},
		DataN=0;
//***Using the Array... DataN=36 at the end.
//***Then I try to delete the old Array to make a new Array
//Method 1
delete[] &Data; // Not Working???
//Method 2
	for(int i=0;i<=DataN;i++)
	{
		delete &Data[i];
	} //Still not working :(
//***Try to make a new Array - But it doesn't work because the old Array's still exist
	int Data[] = {2, 3, -1, 1, 2, 3, -1, 1, 2, 5, -1, 5, -1, 2, 3, 4, -1};
	DataN=0;
}
delete[] should only be used on memory that is allocated with a corresponding call to new[]

The return type of main should be int
Thank cire for the tip. But in this case, what should I do?
Ideally, use a vector.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <vector>
#include <iostream>

template <typename iter>
void print_sequence(iter beg, iter end)
{
    std::cout << "{ ";

    while (beg != end)
        std::cout << *beg++ << ' ' ;

    std::cout << "}\n";
}


int main()
{
    std::vector<int> data = 
    { 
        0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
        0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 
        1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 
        0, 0, 0 
    };
    print_sequence(data.begin(), data.end());

    data = { 2, 3, -1, 1, 2, 3, -1, 1, 2, 5, -1, 5, -1, 2, 3, 4, -2 };
    print_sequence(data.begin(), data.end());
}


http://ideone.com/JTybUJ
Topic archived. No new replies allowed.