On my leisure, I was looking in random college work repos on github and I came across one problem (probably simple) that I couldn't solve.
Write a function that is given two positive integers r, c and allocates a 2-dimensional array with
r rows and c columns. The function then returns a pointer to the allocated array.
This is quite frustrating... for someone with a good knowledge of arrays and pointers, I don't even understand what was asked here.
Has anyone probably solved this somewhere or can you cook up a sample code that can elaborate or probably answer this question?
#include <iostream>
int *TwoDArray(int r, int c);
usingnamespace std;
int main() {
TwoDArray(10, 10);
}
int *TwoDArray(int r, int c) {
int **ary = newint *[r];
for (int i = 0; i < r; ++i)
ary[i] = newint[c];
}