Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: Declaration Question Message-ID: <1242@atanasoff.cs.iastate.edu> Date: 25 Jul 89 00:33:25 GMT References: <394@dftsrv.gsfc.nasa.gov> Reply-To: hascall@atanasoff.cs.iastate.edu.UUCP (John Hascall) Distribution: usa Organization: Iowa State Univ. Computation Center Lines: 32 In article <394> setzer@nssdcs (William Setzer (IDM)) writes: >Will this declaration: >char *foo[K][N]; >allocate the following picture? (i.e. Will it initialize >the pointers properly and allocate memory for all the blocks shown?) >If not, is there a (single) declaration that will? > 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: for (i = 0; i < K; i++) foo[i] = (char*)malloc(K*sizeof(char)); /* checking for NULL from malloc left as an exercise */ John Hascall ISU Comp Center