2d array making dynamically

how to make 2d array dynamicaly

tell me in c++ using new

do u need to understand how to pass it in function argument or
just declare in the function
?

i have not any knowledge of malloc function.

if you don’t know i will repost my doubt

see. I can help u for this

“malloc” or “memory allocation” method in C is used to dynamically allocate a single large block of memory with the specified size. It returns a pointer of type void which can be cast into a pointer of any form. It initializes each block with default garbage value.

Syntax:

ptr = (cast-type*) malloc(byte-size)

this is the approach we used ealier to declare 2D array
int *arr = ( int *) malloc (r * c * sizeof ( int ));

probbably no one makes it this way

but now
suppose we have to make n*m matrix
then we can simply declare

int arr[n][m]

or if u know vectors then

vector<vector<data_type>> name_of_matrix(row , vector(col,initial Value));

vector<vector> dp(n , vector(m,0));

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.