Bonjour;

Je dispose de 4 tablaux à N élement et je veux tester que ma mémoire a bien été alloué dynamiquement, pr cela je fais :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
int *A=NULL,*B=NULL,*C=NULL,*D=NULL;
 
             A=malloc((N)* sizeof(int));
 
	B=malloc((N)* sizeof(int));
 
	C=malloc((N)* sizeof(int));
 
	D=malloc((N)* sizeof(int));
 
	// test si la mémoire a bien été alloué manuellement
 
	if ( (A == NULL || B == NULL) || ( C==NULL || D==NULL) )
    {
        exit(0);
    }
Par ailleur je dispose egalement d une matrice mat[M][N], et j aimerai effectuer le meme test, mais je ne vois pas comment faire

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
int **mat=NULL;
int i;
mat=malloc(M *sizeof(int*)); 
 
	for (i = 0; i < M ; i++)
	{
	mat[i] =malloc(N * sizeof(int));
	}
Merci d'avance