I have the following code:
int **a = new int*[n+1];
for(int i = 0; i <= n; i++) a[i] = new int[1];
Now - to my understanding - the first statement allocates memory for n+1 int pointers, in the loop, for each of these int pointers there 1 * sizeof(int) memory is allocated (a[i] is pointer to the first int).
If I output the array in 2 i = 0 to n loops, it doesn't give a segmentation fault:
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= n; j++)
printf("%d ",a[i][j]);
printf("\n");
}
Why can I access a[i][j] where j > 0, as I only allocated memory for one int, without getting a Segmentation fault?