This program implements the allocation, filling, printing, and deallocation of a dynamically allocated three-dimensional matrix in C.
The program follows these steps:
void fillSizeMatriz(int *x, int *y, int *z)
: Requests the user to enter the three-dimensional matrix dimensions.void mallocMatriz(int ****matriz, int x, int y, int z)
: Dynamically allocates a three-dimensional integer matrix.void fillMatriz(int ***matriz, int x, int y, int z)
: Fills the matrix with user-provided values.void printMatriz(int ***matriz, int x, int y, int z)
: Displays the three-dimensional matrix on the screen.void freeMatriz(int ***matriz, int x, int y, int z)
: Frees the allocated memory for the matrix.gcc array.c -o array
./array
Input:
Enter dimension X: 2
Enter dimension Y: 2
Enter dimension Z: 2
x: 0, y: 0, z: 0 1
x: 0, y: 0, z: 1 2
x: 0, y: 1, z: 0 3
x: 0, y: 1, z: 1 4
x: 1, y: 0, z: 0 5
x: 1, y: 0, z: 1 6
x: 1, y: 1, z: 0 7
x: 1, y: 1, z: 1 8
Output:
1 2
3 4
5 6
7 8
malloc
and free
allows flexible memory allocation, adapting to the user’s needs.