Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!agate!shelby!polya!Gang-of-Four.Stanford.EDU From: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Newsgroups: comp.lang.c Subject: Re: Declaration Question Message-ID: <10847@polya.Stanford.EDU> Date: 25 Jul 89 03:11:25 GMT References: <394@dftsrv.gsfc.nasa.gov> <1242@atanasoff.cs.iastate.edu> Sender: USENET News System Reply-To: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Distribution: usa Organization: Mathematics Department, Stanford University Lines: 37 In-reply-to: hascall@atanasoff.cs.iastate.edu (John Hascall) In article <1242@atanasoff.cs.iastate.edu>, hascall@atanasoff (John Hascall) writes: >In article <394> setzer@nssdcs (William Setzer (IDM)) writes: >>Will this declaration: > >>char *foo[K][N]; > >> foo >> | >> v >>+-------+ +---...---+ >>| ptr1 ------> | N chars | >>+-------+ +---...---+ >>| ptr2 ------> | N chars | >>+-------+ +---...---+ >>| : | | : | > > "char *foo[K][N]" is "array K of array N of pointer to char" which doesn't > match your picture, how about "char (*foo[K])[N]" which is "array K of > pointer to array N of char" which seems to match your picture--and you > will need to malloc the K sets of "N chars" yourself: As I read his diagram, foo is a *pointer* to an array K of pointers to array N of char. So foo is declared: char (*(*foo)[K])[N] and the declaration of foo will only allocate the initial pointer. To allocate everything you have here, you have to malloc space for an array of pointers and then do the same for the characters each of these pointers points to. Dave Eisen (415)723-2963 "work" 814 University Avenue (415)324-9366 home Palo Alto, CA 94301 dkeisen@Gang-of-Four.Stanford.EDU