Dynamically Sized Arrays

In ANSI C arrays are declared with a fixed size. The declaration creates one copy of the array, referenced by its name. Dynamically sized arrays, i.e. those whose size is determined at runtime, are created by declaring a pointer to the element type and using this with calloc().

In C++, as well as declaring fixed size arrays in the same way as in ANSI C, an array of a required type and size can be generated dynamically by using the new operator and may be returned to the heap by the delete operator, as follows.

int main() {
   int *a1;
   ...
   a1 = new int[12];
   return 1;
}

Next note in series - objects

Back to index