1

I have an array points which is a 2d array. The function fillPoints is supposed to fill the array manually with values. I'm getting the Exception EXC_BAD_ACCESS (code=1, address=0x0) on CLion IDE. I suppose there's something wrong with how I handle pointers. This is the code:

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>

#define POINTS_LEN 4
#define A_LEN 200

void fillPoints(int ** pointsArr, int arr_len);

int main() {
    int A[A_LEN];
    int points[2][POINTS_LEN];
    fillPoints(points, A_LEN);

    return 0;
}

void fillPoints(int ** pointsArr, int arr_len) {
    pointsArr[0][0] = arr_len/4;
    pointsArr[0][1] = arr_len/2;
    pointsArr[0][2] = (3*arr_len)/4;
    pointsArr[0][3] = arr_len;

    pointsArr[1][0] = 0;
    pointsArr[1][1] = 1;
    pointsArr[1][2] = 2;
    pointsArr[1][3] = 3;
}
Yos
  • 1,276
  • 1
  • 20
  • 40
  • 1
    An `int[2][4]` isn’t an array of pointers, so you can’t write to it through an `int**`. – Ry- Jul 23 '17 at 08:40
  • 3
    `int ** pointsArr` --> `int pointsArr[][POINTS_LEN]` – BLUEPIXY Jul 23 '17 at 08:42
  • @BLUEPIXY this solved the issue, but what is the difference between `int ** someArray` and `int someArray[][LEN]`? – Yos Jul 23 '17 at 08:45
  • 1
    E.g When `int ** someArray`, `*someArray` is pointer(`int*`). That is, `int ** someArray` means a sequence of `int*`'s., but There is no pointer in the contents of the array. – BLUEPIXY Jul 23 '17 at 08:46

0 Answers0