pointer to array of pointers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

pointer to array of pointers

gustavosserragustavosserra Posts: 201Member
Again this question, but now I hope that someone answer me...

int *(array *)[10];

This is a pointer to an array of pointers to int, correct?
How can I allocate memory to it? Using new for example...
Any help would be appreciated...

Comments

  • rctaylorrctaylor Posts: 9Member
    If I understand what you are trying to do, then if you realize that an array is just a pointer to the beginning of the array in memory, the problem is simple. The way to do it is to define your variable as a double pointer and then allocate the memory however you want:

    [code]
    int** x; //defines a pointer to an int pointer or an array of int pointer
    x = new int*[10] //allocates memory for a 10 element array of int pointer
    [/code]

    : Again this question, but now I hope that someone answer me...
    :
    : int *(array *)[10];
    :
    : This is a pointer to an array of pointers to int, correct?
    : How can I allocate memory to it? Using new for example...
    : Any help would be appreciated...
    :

  • beirowerribeirowerri Posts: 109Member
    If I am right, a pointer to an array of pointers looks like this (your way may be correct too): int** array[500];


  • msmpumsmpu Posts: 1Member
    : Again this question, but now I hope that someone answer me...
    :
    : int *(array *)[10];
    :
    : This is a pointer to an array of pointers to int, correct?
    : How can I allocate memory to it? Using new for example...
    : Any help would be appreciated...
    :

    use pointer to pointer to integers

    #include

    int main()
    {
    // int * (arr *) [10]; this is not correct
    int **aa; // use this trick
    int i;
    // let array has 3 rows and 4 cols
    aa=new int*[3];
    for(i=0;i<3;i++)
    aa[i]=new int[4];

    return 0;
    }

  • gustavosserragustavosserra Posts: 201Member
    Thank you all!!! :-)
    Now Im a happier person!

    : : Again this question, but now I hope that someone answer me...
    : :
    : : int *(array *)[10];
    : :
    : : This is a pointer to an array of pointers to int, correct?
    : : How can I allocate memory to it? Using new for example...
    : : Any help would be appreciated...
    : :
    :
    : use pointer to pointer to integers
    :
    : #include
    :
    : int main()
    : {
    : // int * (arr *) [10]; this is not correct
    : int **aa; // use this trick
    : int i;
    : // let array has 3 rows and 4 cols
    : aa=new int*[3];
    : for(i=0;i<3;i++)
    : aa[i]=new int[4];
    :
    : return 0;
    : }
    :
    :

Sign In or Register to comment.