int** function();
时间: 2023-11-14 16:58:17 浏览: 43
int** function(); 这是一个函数声明,它表示该函数返回一个指向指针的指针的int类型。具体来说,该函数返回一个int类型的指针的指针。
引用中提到的(*a)(int) 是一个类似的函数声明,表示一个指向函数的指针,该函数有一个int类型的参数并返回int类型的值。但是与int** function()不同,它返回的是指向指针的指针。
引用和引用是关于数组在函数参数中的使用的示例。在引用中,函数WrongArrayUse接受一个数组作为参数,但在函数中使用sizeof(my_array)计算数组长度是不正确的。正确的做法是在main函数中计算数组长度,然后将其作为参数传递给函数CorrectArrayUse,如引用所示。
因此,int** function();声明了一个返回指向指针的指针的int类型的函数。
相关问题
std::function<void(int*)>和void(*)(int*)的区别
`std::function<void(int*)>` 是一个可调用对象,可以包含任何可以调用的实体,例如函数指针、成员函数指针、lambda 表达式等。它的类型是一个 function object 类型,可以通过 `std::function` 声明。
`void(*)(int*)` 是一个指向函数的指针类型,它指向一个接受一个 `int*` 类型参数并返回 `void` 的函数。它只能指向函数,不能指向 lambda 表达式或成员函数。
因此,`std::function<void(int*)>` 更加灵活,可以包含函数指针、成员函数指针、lambda 表达式等,而 `void(*)(int*)` 只能指向函数。
int** returnColumnSizes = (int**)malloc(sizeof(int*) * 100);
This line of code allocates memory for an array of 100 integer pointers. The purpose of this array is to store the size of each column in a 2D array.
The syntax used here is known as dynamic memory allocation, which allows the program to request memory from the operating system at runtime. In this case, the size of the memory block is determined by the size of the data type (int*) multiplied by the number of elements (100).
The resulting memory block is then cast to type int**, which is a pointer to a pointer of integers. This means that the array can be treated as a 2D array, with each element pointing to a row of integers.
It is important to note that this memory block must be freed using the free() function when it is no longer needed, to avoid memory leaks in the program.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)