问一个语法问题
想让函数返回一个数组指针,函数类型应该如何写?
#include <iostream>
using namespace std;
/**
Explanation:
The right-left rule:
0. locate the specififer: f in this exmaple
1. look at its right: () in this case, hence f is a function
2. look at its left: * in this case, hence f returns a pointer
3. look at (*f())'s right: [10], hence f is a function which returns a pointer to an array of 10 elements
4. look at (*f())'s left: int, hence f is a function which returns a pointer to an array of 10 ints.
*/
int (*f())[10];
int main()
{
f();
return 0;
}
int (*f())[10]
{
int (*p)[10] = new int[5][10];
return p;
}
强的。很好