Thread: Want to now what is the use of double pointer

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    1

    Want to now what is the use of double pointer

    Hi friends,

    I'm new to c programming..........I need to know what is the use of double pointer and when will we use it?


    Thanks
    Ammu
    Last edited by ammu; 11-10-2008 at 07:12 AM. Reason: error

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you talking about something like this:
    int **ptr;
    ??
    The same reason as you'd have a pointer to integer vs. the integer itself.

    A double pointer is simply an address of another pointer. The most common use is as an argument to a function where you need to be able to modify the pointer itself - so you need to have a pointer to the pointer, otherwise it can't be modified.

    Another common case is two-dimensional arrays with dynamic sizing, in which case you'd have a pointer to a set of pointers to the actual data.

    If you are asking about:
    double *ptr;
    then the question is "why do we need a pointer", and the above sort of explains some of that, but perhaps you would like to show us some code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well the first ever example you come across is this
    int main ( int argc, char **argv )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Salem View Post
    Well the first ever example you come across is this
    int main ( int argc, char **argv )
    That is of course if the author didn't decide to do:
    Code:
    int main ( int argc, char *argv[] )
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer with double asterisk
    By skringla in forum C Programming
    Replies: 10
    Last Post: 11-27-2008, 07:33 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  4. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  5. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM