auto function(int i) -> int(*)[10]{
}
Can anyone help me how to return a pointer to array of 10 integers using trailing return type? Any example will be helpful.
#include <iostream>
const size_t sz = 10;
auto func(int i) -> int(*)[sz] /// returns a pointer to an array of ten ints
{
static int arr[sz];
for (size_t i = 0; i != sz; ++i)
arr[i] = i;
return &arr;
}
int main()
{
int i = 2;
int (*p)[sz] = func(i); /// points to an array of ten ints which funct returns which is arr array
for (size_t ind = 0; ind != sz; ++ind) /// displays the values
std::cout << (*p)[ind] << std::endl;
return 0;
}
auto function (int i) -> int(*)[sz]
to return a pointer to an array of ten int
int i = 2; int (*p)[sz] = funct(i);