how to make a dynamic 2d array in c++ code example
Example 1: Create dynamic 2d array in java
import java.util.ArrayList;
import java.util.List;
public class Dynamic2dArray
{
public static void main(String[] args)
{
List<int[]> li = new ArrayList<>();
li.add(new int[]{2,4,6});
li.add(new int[]{3,5});
li.add(new int[]{1});
System.out.println("Element at [0][0]: " + li.get(0)[1]);
System.out.println("Element at [1][1]: " + li.get(1)[1]);
}
}
Example 2: declaring 2d dynamic array c++
int** arr = new int*[10];
int i=0, j;
for (i; i<10; i++)
arr[i] = new int[5];
Example 3: array 2d dynamic allocation c++
int** a = new int*[rowCount];
for(int i = 0; i < rowCount; ++i)
a[i] = new int[colCount];