0
Help me with allocating arrays with dynamic length(variable length)
How to allocate an array with a dynamic size? This might seem like a basic question, but how do we allocate a nxn array with n being the input? I tried something, but it's probably the worst way to do this https://code.sololearn.com/cHWMUP0BEIeA/?ref=app
2 Réponses
+ 2
You can dynamically allocate a 2D array like;
int **arr = new int*[size];
for (int k{0}; k < size; ++k) {
arr[k] = new int[size];
}
0
ChaoticDawg ooh yes I didn't think about this way, thank you