previous | index | next

Creating and Accessing Dynamic Arrays

Suppose we want to use the variable v to name the array in our program, so we try:
  int v = new int[n];
Q: Is this correct?

A: Since new returns a pointer to an integer, it needs to be:
  int* v = new int[n];
Now elements of the array can be accessed with the usual v[index].

previous | index | next