f



pointer to pointer

hi
could someone tell me a good website that explains pointer to pointers well. 
Not just simple stuff like 2d arrays passing , or pointing to another int 
variab.le 


0
5/30/2006 11:25:33 AM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

3 Replies
503 Views

Similar Articles

[PageSpeed] 15

jagguy wrote:

> hi
> could someone tell me a good website that explains pointer to pointers well. 
> Not just simple stuff like 2d arrays passing , or pointing to another int 
> variab.le 
> 
> 

Not sure that there is one - how hard can it be really.
*p returns a reference to whatever p points to. If p points to a pointer,
**p returns a reference to whatever that pointer points to.

There's one for function pointers though, since they have tricky syntax (function-pointer.org ?).

What do you want to do?
Many times pointer wrangling can be replaced by something safer and easier to work with.

Sorry to be of little help

	homsan
0
5/30/2006 11:54:24 AM
jagguy posted:

> hi
> could someone tell me a good website that explains pointer to pointers
> well. Not just simple stuff like 2d arrays passing , or pointing to
> another int variable


A pointer variable stores a memory address. Plain and simple.

If it's a pointer variable of any kind, it stores a memory address.

The following variable stores an integer:

    int k;


The following variable stores a memory address:

    int *p;


It doesn't just store ANY memory address though, it's supposed to store 
the memory address of an "int".

How do we store the memory address of an "int*". Simple, with a pointer 
to an "int*":


int **pp;


Here's a sample:

int main()
{
    int k = 5;

    int *p = &k;

    int **pp = &p;

    int ***ppp = &pp;

    int ****pppp = &ppp;

    int *****ppppp = &pppp;


    *****ppppp = 7;

}


-Tom�s
0
Tom
5/30/2006 4:26:52 PM
Here is slightly complicated example using **pointers:

class Boo
{
  int  num;
  Boo* next;
} ;

void main()
{
Boo emp1, emp2, *pointer0, **pointer1;

pointer0 =&emp1; //point pointer0 to emp1

*pointer1 = &pointer0; //point pointer1 to wherever pointer1 is
pointing to

(*pointer1)->next = &emp2; //use pointer1 to set next of emp1 to point
to emp2

(*pointer1)->num = 5; //use pointer 1 to set emp1's num to 5

return ;
}




jagguy wrote:
> hi
> could someone tell me a good website that explains pointer to pointers well.
> Not just simple stuff like 2d arrays passing , or pointing to another int
> variab.le

0
5/31/2006 9:35:33 AM
Reply: