Mail Archives: djgpp/1998/02/10/01:22:43
Jason Alexander wrote:
>
> Can someone explain to me how to dynamically declare a 2-d array?
> I know the following code works for dynamically declaring a 1-d array
> of integers, but I don't see how to extend it to the 2-d case.
>
> int main(void) {
> int i;
> int *array;
>
> printf("Array dimension: ");
> scanf("%d", &i);
> array = (int *) malloc(i*sizeof(int))
> }
GCC has special feature which allows to declare arrays dynamically :
int foo(ibt x,int y)
{ int arr[x][y];
...
}
That's all.
Note, this is a specific gcc feature, so it's not portable to other
compilers.
--
____ ____
| \ / Dim Zegebart
____/____
Moscow Russia
WWW - http://www.geocities.com/siliconvalley/pines/7817
DZcomm - comm library for Allegro
Palantir - multytasking kernel for Allegro (based on PDMLWP)
- Raw text -