I allocated the array as follows.
#include <iostream>
int main() {
const int first_dim = 3;
const int second_dim = 2;
int** myArray = new int*[first_dim];
for (int i = 0; i < first_dim; i++) {
myArray[i] = new int[second_dim];
for (int j = 0; j < second_dim; j++) {
myArray[i][j] = i*second_dim + j;
std::cout << "[i = " << i << ", j = " << j << "] Value: " << myArray[i][j] << "\n";
}
}
for (int i = 0; i < first_dim; i++)
delete[] myArray[i];
delete[] myArray;
}
Let's say I want to add a fourth element to the first dimension, i.e. myArray[3]. Is it possible?
I heard that Vectors are much more efficient for this purpose, but I don’t know what it is, and I have never used them before.
source
share