|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Dynamic 2d Arrays
I believe that the following code is correct for creating a dynamic 2d array K(which is a **int) :
int **K; int n; /* Create a pointer to each row of the matrix. */ K = (int **)malloc(size * sizeof(int *)); /* Create each row of the matrix */ for(n = 0; n < size; n++) K[n] = (int *)malloc(size * sizeof(int)); My question is: If I refer to an element in K, is it valid to use subscripts(ex. K[1][1])? Is the memory region created by my code analgous to the memory region generated by a statitic 2d declaration(ex. int K[size][size])? I have had no problems yet, however I am worried that I will find a problem later. Thanks |
|
#2
|
||||
|
||||
|
http://www.eskimo.com/~scs/C-faq/q6.16.html
The FAQ on this page answers both your questions. Hope this helps ![]() |
|
#3
|
|||
|
|||
|
Thank you! Excellent response!(That second method in the FAQ, however, looks horrible.
) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Dynamic 2d Arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|