Think C: dynamic 2d array allocation

Mike J. Kelly mike at odgate.odesta.com
Fri Apr 26 06:57:26 AEST 1991


In article <frost.672455128 at watop> frost at watop.nosc.mil (Richard Frost) writes:
>I am trying to dynamically allocate space for a 2d array USING Think C 4.0
>(on a Macintosh IIci).  Here's what I've tried:
>
>------------------------
>#define	max_el	128
>#define	max_az	2048
>
>int		el, az;
>unsigned int	**image;	
>
>	**image = (unsigned int **) malloc(max_el * sizeof(unsigned int *));

	^^ this deferences an undefined pointer.  **image is of type
	unsigned int, but you're assigning a pointer to pointer value to
	it.  What I think you want is:

	image = (unsigned int **) malloc(max_el * sizeof(unsigned int *));



More information about the Comp.lang.c mailing list