yes you can.
using the "new" keyword
Code:
int * array = NULL;
int size;
cout << "What size do you want array to be?\n";
cin >> size;
array = new int [size];
if( array == NULL)
{
cout << "Error, not enough mem to create array" << endl;
}
array can now be acessed like a regular array, using brackets
array[index], and index must be in the range 0..size-1.
Once you are done with array give the memory back with delete
Code:
delete [] array;
array = NULL;
new returns a pointer to what ever type you pass it.
type * new type [size];
the size inside brackets is optional.
Code:
int * CreatedWithNew = NULL;
CreatedWithNew= new int;
*CreatedWithNew = 10;
//blah blah
delete CreatedWithNew;
CreatedWithNew = NULL;
Notice in that call to delete i did not need to use the [] before the var name. That is becuase i only created 1 int. When you pass delete the [] it tells delete to clear all the vars created with new. If you dont pass it the [], it will only clear the first var.
You should make sure you delete all memory you create with new to avoid memory leaks. A memory leak is when you get memory from new, then never delete it. The operating system then loses that memory for other programs, or future calls to new, and wont get it back until a reboot. New can be used with any data type.