mercredi 4 janvier 2017

Point to specfic rows of 2-D arrays

I wrote the following code to point to first row of a 2-dimensional array. However, when I do so "arrayPtr = & array[0];" I end up getting

error: cannot convert 'double (*)[1]' to 'double*' in assignment
  arrayPtr = & array[0];

My program is:

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    double array[2][1];
    array[0][1]=1;
    array[1][1]=2;

    double* arrayPtr;
    arrayPtr = & array[0];

    return 0;
}

Can someone help me understand as to where am I going wrong?

Aucun commentaire:

Enregistrer un commentaire