pointer to pointer

J

jagguy

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
 
H

homsan toft

jagguy said:
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
 
T

Tomás

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
 
U

uraniumore235

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 ;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top