malloc and 'free' exists in C++. You can use 'new' and 'delete' instead, however.
int* x = new int[10] makes an array of 10 ints.
delete[] x;
deletes the array pointed to by x.
new and delete call constructors, while malloc and free do not. This is more important when you are writing real C++ code.
std::vector's are what you want for dynamic arrays in C++. Really.
__________________
Last edited by JHVH : 10-29-4004 BC at 09:00 PM. Reason: Time for a rest.
|