+ 3
How can I create a 2D dynamic array using malloc() in C?
I want to create a program that multiply two matrices which dimensions are two variables (i and j). I can't understand how to use malloc() to allocate the right amount of memory and how to use it. I am developing using Visual Studio 2015.
3 Réponses
+ 2
int **arr = (int **)malloc(row * sizeof(int *));
for (i=0; i<row; i++)
arr[i] = (int *)malloc(column * sizeof(int));
for more details check out:
http://www.geeksforgeeks.org/dynamically-allocate-2d-array-c/
+ 1
no problem 😀
0
Thank you very much Nikunj Arora! 😉