#include <stdio.h> #include <stdlib.h> #include <conio.h> int main() { int **a; int L=2, C=2, i, j; //Allocation de a[2][2] a = (int**)malloc(sizeof(int*) * L); for(j=0 ; j < L ; j++ ) { a[j] = (int*)malloc(sizeof(int) * L); } //Reallocation on passe de a[2][2] à a[4][5] L = 4; C = 5; a = (int**)realloc(a, sizeof(int*) * L); for(i=0 ; i < L ; i++ ) a[i] = (int*)realloc(a[i], sizeof(int) * C); for(j=0 ; j < L ; j++) { for(i=0 ; i < C ; i++) { a[j][i] = i+1; } } for(j=0 ; j < L ; j++) { for(i=0 ; i < C ; i++) { printf("%d\t", a[j][i]); } printf("\n"); } getch(); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question