dynamic multi.txt
来自「bankers algorithm calender colour」· 文本 代码 · 共 47 行
TXT
47 行
/* allocate2D
/* function to dynamically allocate 2-dimensional array using malloc.
/*
/* accepts an int** as the "array" to be allocated, and the number of rows and
/* columns.
*/
void allocate2D(int** array, int nrows, int ncols) {
/* allocate array of pointers */
array = ( int** )malloc( nrows*sizeof( int* ) );
/* allocate each row */
int i;
for(i = 0; i < nrows; i++) {
array[i] = ( int* )malloc( ncols*sizeof( int ) );
}
}
/* deallocate2D
/* corresponding function to dynamically deallocate 2-dimensional array using
/* malloc.
/*
/* accepts an int** as the "array" to be allocated, and the number of rows.
/* as with all dynamic memory allocation, failure to free malloc'ed memory
/* will result in memory leaks
*/
void deallocate2D(int** array, int nrows) {
/* deallocate each row */
int i;
for(i = 0; i < nrows; i++) {
free(array[i]);
}
/* deallocate array of pointers */
free(array);
}
/* EXAMPLE USAGE:
int** array1;
allocate2D(array1,1000,1000); //allocates a 1000x1000 array of ints
deallocate2D(array1,1000); //deallocates the same array
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?