Search code examples
c++arrayspointersdynamic-arrays

Assigning to int from Compatible type int


In the bolded part, I am having compile error. some one help to find out error? my code is given below...

void _multiDimensionalArray(){

    int row = 10;
    int column = 10;
    cout << "\n\n For a 2-Dimensional Array:>>>>" << endl;

    // 2D array is basically an array of pointers to arrays
    // dynamic array of size 100
    int pDoubleArray = new int*[row];
    for (int i=0; i<column; i++) {
        pDoubleArray[i] = new int[column];
    }
    // e) exchange rows: 0<------>9 and 3<------>4
    int (*ptemp)[10][1];        // temp is a pointer to an array of 10 ints
    ptemp = pDoubleArray;

    for (int i=0; i<10; i++) {
        ptemp[i][0] = *(ptemp+4);
    }
    for (int i=0; i<10; i++) {
        cout << ptemp[i] << " " ;
    }


 } // end of _multiDimensionalArray function

Solution

  • You need to only reference the first value of the pointer. Once you reference the first pointer, at every other word length depending upon the data type, the reference is made.