pointers to pointers

Discussion in 'C Programming' started by defcon8, Oct 6, 2005.

  1. defcon8

    defcon8 Guest

    Could someone paste an example of why pointers to pointers could be
    needed please?
     
    defcon8, Oct 6, 2005
    #1
    1. Advertising

  2. defcon8

    Eric Sosman Guest

    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.

    --
     
    Eric Sosman, Oct 6, 2005
    #2
    1. Advertising

  3. defcon8

    Alex Fraser Guest

    "defcon8" <> wrote in message
    news:...
    > 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
     
    Alex Fraser, Oct 6, 2005
    #3
  4. "defcon8" <> wrote in message
    news:...
    > 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
     
    Alexei A. Frounze, Oct 6, 2005
    #4
  5. defcon8

    Mike Wahler Guest

    "defcon8" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Oct 6, 2005
    #5
  6. defcon8

    Dale Guest

    "defcon8" <> wrote in news:1128624147.466368.32080
    @z14g2000cwz.googlegroups.com:
    >
    > Could someone paste an example of why pointers to pointers could be
    > needed please?
    >


    A dynamic list of dynamic lists.
     
    Dale, Oct 7, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil
    Replies:
    1
    Views:
    666
    llewelly
    Sep 16, 2003
  2. muser
    Replies:
    3
    Views:
    780
    Ron Natalie
    Sep 18, 2003
  3. A
    Replies:
    3
    Views:
    471
    Alan Kelon
    Oct 29, 2003
  4. Xamalek
    Replies:
    7
    Views:
    700
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    714
Loading...

Share This Page