By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

matrix memory allocation

P: n/a
Is it possible to allocate dinamically memory for a bidimensional array?
Jun 12 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

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


Yes.

Homework.

Tom

Jun 12 '06 #2

P: n/a
acab said:
Is it possible to allocate dinamically memory for a bidimensional array?


In your dutifully careful perusal of the FAQ, you unaccountably appear to
have overlooked the following:

<http://c-faq.com/aryptr/dynmuldimary.html>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jun 12 '06 #3

P: n/a
In article <JM********************@twister1.libero.it>,
acab <pi************@yahooDOT.com> wrote:
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

--
Dave Vandervies dj******@csclub.uwaterloo.ca

If being concerned with accuracy makes me a jerk, I plead guilty.
--Richard Heathfield in comp.lang.c
Jun 12 '06 #4

P: n/a
Richard Heathfield wrote:
acab said:

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

In your dutifully careful perusal of the FAQ, you unaccountably appear to
have overlooked the following:

<http://c-faq.com/aryptr/dynmuldimary.html>


I'll be careful next time,
thanks for helping!
Jun 12 '06 #5

P: n/a
On 2006-06-12, Dave Vandervies <dj******@caffeine.csclub.uwaterloo.ca> wrote:
In article <JM********************@twister1.libero.it>,
acab <pi************@yahooDOT.com> wrote:
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.


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

This discussion thread is closed

Replies have been disabled for this discussion.