double pointer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cool17
    New Member
    • Oct 2006
    • 24

    double pointer

    hey guys

    what do u mean by double pointer in c++???

    thank
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    it means something like

    int **

    this is a pointer to a pointer to an integer

    it could be used in this (very contrieved) way

    Code:
    #include <iostream>
    
    using namespace std;
    
    void allocInt( int **ppi)
    {
        *ppi = new int;
    
        **ppi = 5;
    }
    
    void freeInt( int *pi)
    {
        delete pi;
    }
    
    int main()
    {
        int *myInt;
    
        allocInt(&myInt);
    
        cout << *myInt << "\n";
    
        freeInt(myInt);
    
        return 0;
    }
    In any function where we want to return a data via a parameter we have to use a pointer to the type we want to return. Since in allocInt we want to return an int * via a parameter we need a pointer to that type int **.

    Comment

    • cool17
      New Member
      • Oct 2006
      • 24

      #3
      thank you...it really make me understand better now.

      Comment

      Working...