Making 2D array with malloc()
so I'm trying out some used in malloc and generally understand how to use it for 1d arrays, but having trouble with 2d arrays.
So I just want to to create a 2d array with all 1's. Would also be great to differentiate the first array from the second. I.e. first array has 3 second has 10;
Thanks!!
Code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int ** test;
int size = 3;
test = (int**) malloc (size*sizeof(int));
for(int o = 0; o<size; o++)
{
for(int i=0;i<size;i++)
{
test[o][i] = 1;
cout << test[o][i];
}
}
return 0;
}