pointers to pointers

D

defcon8

Could someone paste an example of why pointers to pointers could be
needed please?
 
E

Eric Sosman

defcon8 wrote On 10/06/05 14:42,:
Could someone paste an example of why pointers to pointers could be
needed please?

Second argument to main().

Second argument to strtod(), strtol(), and so on.

Both arguments to the comparison function called by
qsort(), when you're using it to sort an array of pointers.
 
A

Alex Fraser

defcon8 said:
Could someone paste an example of why pointers to pointers could be
needed please?

There are a few standard library functions that use them, eg strtol().

Alex
 
A

Alexei A. Frounze

defcon8 said:
Could someone paste an example of why pointers to pointers could be
needed please?

When you want the called function to modify some variable defined in the
calling function locally (or a global variable), you pass a pointer to that
some variable to the function. It may happen that that some variable is also
a pointer. Example, you may want a function to malloc() a buffer and somehow
return the pointer to it to the caller, yet you cannot return it by return
(if it's for instance used for telling the error code).

If you don't like pointers, try Java. Or even better Basic or Matlab. The
latter don't generally have a good idea of what a pointer/address/reference
is. :)

But really, there are uses for many things that are possible in the
language. Some things may be misused. Some uses may be unknown to you, but
neither means there shouldn't be such or such feature...

Alex
 
M

Mike Wahler

defcon8 said:
Could someone paste an example of why pointers to pointers could be
needed please?

Same reason you'd need a pointer to any other
type. Pointers are typically used as function
parameter(s) when the function needs to modify
its argument(s). If one of those arguments
has a pointer type, then we need a 'pointer-to-
pointer' parameter.

If you don't need them, don't use them.

-Mike
 

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

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top