home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.programmer
- Path: sparky!uunet!psinntp!cgrafx!msb
- From: msb@chromagrafx.com (Michael S. Barthelemy)
- Subject: Re: Stupid question: What does ** mean?
- Message-ID: <1992Jul24.133729.2290@chromagrafx.com>
- Sender: msb@chromagrafx.com
- Organization: Chromagrafx Imaging Systems, Hauppauge, NY
- References: <1992Jul22.225838.13892@vlsisj.uucp>
- Date: Fri, 24 Jul 1992 13:37:29 GMT
- Lines: 50
-
- In article <1992Jul22.225838.13892@vlsisj.uucp>
- smadsen@leland.Stanford.EDU (Steve Madsen) writes:
- > Here's an easy one. . .I'm stumped by the double asterisk declaration,
- > for example:
- >
- > (int **)
- >
- > I've tried to locate it in Chapter 3, 6 and 7 of NextStep Concepts, as
- > well as two different C manuals, so it's not a pure RTFM question (I
- > hope). . .
-
- It's a double pointer. (i.e. A pointer to another pointer.) If you were
- to write:
-
- int **temp;
-
- It can be referenced several ways though.
-
- temp[x] would give you the x'th element of the pointer array.
- (which would be another pointer)
-
- temp would give you the first element (pointer)
- (such that temp has not been changed)
-
- When mallocing one of these structures by yourself you will have to first
- malloc for the first pointer to the array and then malloc off all of the
- pointers to fill the array:
-
- extern struct foo;
- extern int numElements;
- struct foo **fooItems;
-
- {
- int i;
-
- fooItems = (struct foo **) malloc(sizeof(struct foo *) *
- numElements);
- for (i = 0; i < numElements; i++)
- fooItems[i] = (struct foo *) malloc(sizeof(struct foo));
- }
-
- You can procede down the pointer path a long ways. The most I have ever
- used are five and I am not sure if there is a limitation as to how many
- one can have.
-
- It happens to be referenced on pages 107-110 in K&R but they do not use a
- terribly good example to show a double pointer.
-
- Mike Barthelemy
- msb@chromagrafx.com
-