:: Re: [DNG] Making sense of C pointer…
Top Pagina
Delete this message
Reply to this message
Auteur: karl
Datum:  
Aan: dng
Onderwerp: Re: [DNG] Making sense of C pointer syntax.
Edward Bartolo:
> KatolaZ wrote:
> >> c) type **ss; // declare a pointer to pointer. System only allocates
> >> space for one address
>
> > C pointers are *always* one variable, precisely a variable large
> > enough to store a memory address on the current architecture.
>
> I think, I did not understand what you want to say. As far as I can
> imagine a pointer to pointer is something like this:
> [pointer1]------>[pointer2]------->[data] int the case of data** dt.

...

To be picky, "int ** id;", just defines an allocates one variable id
that when used like **id will have the type int. It says nothing about
what value id, *id, **id will have, nor if *id or **id will be in any
way useful.

For **id be useful *id has to have some defined value, e.g.

int main(void) {
  int  data     = 4;
  int * pointer1 = & data;
  int ** pointer2 = & pointer1;
  int *** pointer3 = & pointer2;
  int **** pointer4 = & pointer3;
  /* etc... */
  return **** pointer4;
}


$ gcc -Wall a.c; ./a.out; echo $?
4

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57