I am facing to an issue when I want to allocate a memory for a problem of size n = 32678 a 2D array of size tab[2n][n+1]. This is a code :
#include <stdio.h>
#include <stdlib.h>
int main(){
int n = 32768;
unsigned int** tab = (unsigned int**) malloc(2 * n * sizeof * tab);
if(tab == NULL){
printf("insuffisant memory\n");
exit(EXIT_FAILURE);
}
tab[0] = (unsigned int*) malloc(2 * n * (n+1) * sizeof * tab[0]);
if(tab[0] == NULL){
printf("insuffisant memory\n");
exit(EXIT_FAILURE);
}
for(int i = 1; i < 2 * n; i++)
tab[i] = tab[0] + i * (n+1);
tab[2*n - 1][0] = 0;
}
The last instruction end up to an error:
Segmentation fault (core dumped)
I don't understand what happen because I don't have problem when n = 1 to 32767. From n = 32768 I have this error.
Please do you understand what happen?