用c创建一个1920*864的二维数组
时间: 2023-12-09 21:55:24 浏览: 31
以下是创建一个1920*864的二维数组的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
int main() {
int rows = 1920;
int cols = 864;
// allocate memory for the 2D array
int** arr = (int**) malloc(rows * sizeof(int*));
for (int i = 0; i < rows; i++) {
arr[i] = (int*) malloc(cols * sizeof(int));
}
// initialize the array with some values
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
arr[i][j] = i + j;
}
}
// print the array
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
// free the memory allocated for the array
for (int i = 0; i < rows; i++) {
free(arr[i]);
}
free(arr);
return 0;
}
```
这个程序首先定义了行数和列数,并使用 `malloc()` 函数动态分配了一个二维数组。然后,程序使用嵌套的循环对这个数组进行初始化,并将其打印出来。最后,程序释放了分配的内存。