Re: dynamically allocating a 2d array
- From: "Nerox" <nerox0@xxxxxxxxx>
- Date: 10 Sep 2005 09:48:22 -0700
Stick to the following rule:
-Generally, an array name in an expression is evaluated as a pointer to
its first element.
Thus,
int array[Y][X] is a 2d array, an array of Y arrays of X integers.
You can write its dynamic counterpart as follows:
int (*array)[X] which is a pointer to an array of X integers.
And then allocate it dynamically via malloc:
array = malloc(sizeof(*array) * Y );
.
- Follow-Ups:
- Re: dynamically allocating a 2d array
- From: Keith Thompson
- Re: dynamically allocating a 2d array
- References:
- dynamically allocating a 2d array
- From: junky_fellow
- dynamically allocating a 2d array
- Prev by Date: Re: Floating Point Precision
- Next by Date: Re: Float to String
- Previous by thread: Re: dynamically allocating a 2d array
- Next by thread: Re: dynamically allocating a 2d array
- Index(es):
Relevant Pages
|