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

8th Aug 2021, 2:21 AM
Rishi
Rishi - avatar
2 ответов
+ 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]; }
8th Aug 2021, 3:48 AM
ChaoticDawg
ChaoticDawg - avatar
0
ChaoticDawg ooh yes I didn't think about this way, thank you
8th Aug 2021, 5:36 AM
Rishi
Rishi - avatar