Dynamic Arrays

I'm wondering about the actual benefits of using new and delete in regards to arrays. I just don't see a difference in

int array[10];
cin.getline(array,10);

and

int* array = new int[10];
cin.getline(array,10);

If someone could explain, it would be much appreciated.
dynamic allocation works with variable lengths:
1
2
3
int len;
cin>>len;
int* array=new int[len]; //works fine 

static doesn't:
1
2
3
int len;
cin>>len;
int array[len]; //doesn't work 
if I want two dimentional dynamic array ,how I can use it
1
2
3
4
5
6
7
8
9
10
11
12
13
14

     int N;
     cout<<"Enter N:";
     cin>>N;
     int point[N][2]; //here I take  "expression must have constant value" in visual 2010
     cout<< endl;
     for(int i=0;i<N;i++)
		{
          cout<<" Enter x , y :";              
          cin>>point[i][0];
          cin>>point[i][1];
		}

Last edited on
1
2
const int N = 5; // this means constant it's needed for static aloc.
int point [N] [2]; // now work's 

OR

1
2
3
4
int N;  // when using dynamic aloc. no const is needed for first dim
cin >> N;
int* point = new int [N] [2];
delete point [];  //delete dynamic array (not needed for static array's 
Last edited on
1
2
3
4
int N; 
cin >> N;
int* point = new int [N] [2];// error a value of type "int(*)[2]" cannot be used to initialize an entity of type "int*"
delete point [];  
Last edited on
1
2
3
4
int N; 
cin >> N;
int* point [N] = new int [N] [2];// I'm sorry forgot to put [n] after point
delete point [];  
Last edited on
thank you very much but i take same error always
1
2
3
4
int N; 
cin >> N;
int* point [N] = new int [N] [2];// "expression must have constant value"
delete point [];  
sorry man I realy f.. up twice LOL:D
now work's
1
2
3
4
int N; 
cin >> N;
int (*point) [2] = new int [N] [2];
delete [] point; 

Last edited on
thank you again you really helped to me
Topic archived. No new replies allowed.