I would like to ask you about some doubt I have about memory allocation with calloc;
I am trying to create a bool 2d matrix which would be represented by 0 for false and 1 for true. I have the following code:
// Create a 2D array
int **createArrayBool(int row, int col){
// Allocate memory for 2D array
int **arr = (int**) calloc(row,sizeof(int*));
for ( int i = 0; i < row; i++ ){
arr[i] = (int*) calloc(col,sizeof(int));
}
return arr;
}
In main() I called the function:
int **arr2d = createArrayBool(2,2);
My doubt is that when I print the value let’s say at position arr2d[1][5] I got 0 but I only allocated col < 2 and I did not get an error.
Thank you for your answer.