matrix memory allocation

D

Dave Vandervies

Is it possible to allocate dinamically memory for a bidimensional array?

Yes.


Oh, you wanted to know how?

You can either allocate a single array of m*n values and calculate
the index into that array from the row and column index, or allocate m
arrays of n values plus an array of m pointers and index using the row
and column indices separately.
(Setting things up so that you can use either of these methods is left
as a (fairly simple) exercise.)


dave
 
B

Ben C

Yes.


Oh, you wanted to know how?

You can either allocate a single array of m*n values and calculate
the index into that array from the row and column index, or allocate m
arrays of n values plus an array of m pointers and index using the row
and column indices separately.

You can also assign the result of a single malloc to a "pointer to
array" type and use a[j] syntax to access the members. This is in the
FAQ as well so I won't go into it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top