0

I'm trying to send a 2D array (int arr[5][5], initialized with numbers) to a function, the prototype of the function is:

int function(int **arr, int size, int *pi, int *pj);

so I type in main():

size=function(arr, 5, &i, &j);

(i and j are not initialized)

I'm getting an error "Access violation reading location" which tells me it can't read from the array, because it isn't pointing anywhere.

The prototype cannot be changed, how can I fix it?

J...S
  • 5,079
  • 1
  • 20
  • 35
NirBar6
  • 1
  • 1
  • 1
    _the prototype cannot be changed_ : `int arr[5][5]` and `int **arr` are not compatible. So Correction is impossible. – BLUEPIXY Sep 29 '17 at 18:53
  • @BLUEPIXY: in caller: `int arr[5][5]; int *iptr[5]; iptr[0] = &arr[0][0]; iptr[1] = &arr[1][0]; iptr[2] = &arr[2][0]; iptr[3] = &arr[3]0]; iptr[4] = &arr[4][0]; function(iptr, size, pi, pj);`. The problem here is the common misconception that if a single-indirected pointer-to-type is "the same as" an array-of-type, then obviously a double-indirected pointer-to-type is "the same as" a 2D-array-of-type, which is clearly a false belief. – Bob Jarvis - Слава Україні Sep 29 '17 at 22:09
  • As an example: https://ideone.com/OBWIu4 – Bob Jarvis - Слава Україні Sep 29 '17 at 22:40

0 Answers0