Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!decwrl!mcnc!thorin!currituck!morse From: morse@currituck.cs.unc.edu (Bryan Morse) Newsgroups: comp.lang.c Subject: Re: Novice question. Message-ID: <17265@thorin.cs.unc.edu> Date: 3 Nov 90 15:26:01 GMT References: <1990Oct31.014132.2400@agate.berkeley.edu> <336@brat.UUCP> Sender: news@thorin.cs.unc.edu Reply-To: morse@currituck.cs.unc.edu (Bryan Morse) Organization: University Of North Carolina, Chapel Hill Lines: 63 In article <336@brat.UUCP> donn@brat.UUCP (Donn Pedro) writes: >A question for you that know, because I dont. > > >I understand that the following is a pointer. > >> char *s; > >But what is this doing? >Why the two "*". > >> STRING **s_array; > >Please e-mail. I'm posting my reply since the mail I sent you bounced. Besides, maybe someone else wants to know (and if someone doesn't, my apologies). First, the real way to read C declarations. Any statement of the form type says that all expressions in the list are of the specified type. Thus, the statement char *s; does not (repeat, does *not*) say that s is a pointer to a char. What it says is that *s is a char. It may seem the same (and in reality is) but it's important to make the distinction. That's why you can say char c, *s; and declare both a char and a pointer to one. A very common mistake is to say "hmm, I want to declare a few char pointers" and type char * s,t; ------ --- type list of variables and this is WRONG! Be very careful to think in terms of this C style instead of the Pascal style where you specify the type (including pointers) and a list of variables. Does this make sense? Having said this, let's get to your question: STRING **s; says that **s is of type STRING. Since *s is what s points to and **s is what *s points to (you can chain dereferences in C like what--similar to p^^ in Pascal if you've every seen it) that means that s is a pointer to a pointer to a STRING. Make sense? Seriously, once you learn this simple rule of how to read C declarations, you can understand even the most convoluted declarations. Hope this helps.. Bryan Morse University of North Carolina at Chapel Hill morse@cs.unc.edu Department of Computer Science