int** a = new int* [row]
时间: 2023-11-14 20:38:44 浏览: 37
这行代码是在动态分配一个二维数组,其中 `row` 是数组的行数。它创建了一个指向指针的指针 `a`,并将 `a` 指向一个长度为 `row` 的整型指针数组。每个指针指向另一个整型数组,从而实现了一个二维数组。这种方法可以灵活地分配内存,因为可以在运行时确定数组的大小。但是,使用完数组后一定要记得释放内存,否则会造成内存泄漏。
相关问题
int** matrix = new int*[row];中**是做什么的
在 C++ 中,** 表示一个指向指针的指针,也叫做二级指针。在 int** matrix = new int*[row]; 语句中,它表示 matrix 是一个指向指针的指针,也就是说 matrix 是一个指针数组,其中每个元素又是一个指针。实际上,这个语句创建了一个包含 row 个指针的数组,每个指针都指向一个 int 类型的数组。因此,这个语句可以用于创建一个动态二维数组。需要注意的是,在使用完该数组后,需要使用 delete[] 释放内存,以免发生内存泄漏。
int** c; c = new int* [m+1];
This code creates a dynamic 2D array of integers with m rows and 1 column, and assigns the memory address of this array to the pointer variable c.
Note that the syntax for dynamically allocating a 2D array involves creating an array of pointers to arrays, where each pointer points to a dynamically allocated array of integers.
In this case, we are creating an array of m pointers, and each pointer will point to an array of 1 integer.
To access an element in this 2D array, we would use the syntax c[i][j], where i represents the row index and j represents the column index.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)