You can't assign an array in C or C++, only pointers (to arrays).
The second point is that you can't return a pointer to a local variable, because the variable goes out of scope (and the pointer becomes invalid) when the function exists. To counter this, we can make the variable static (see code).
Eg.
Code:
#include<stdio.h>
float (*func1 ( void ) )[2] {
static float twoDarray[4][2] = {
{ 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }
};
return twoDarray;
}
void func2 ( void ) {
float (*var)[2] = func1();
printf( "%f\n", var[1][1] );
}
/*
* But the raw pointer notation can get heavy (and obscure)
* so a typedef can make the code much more readable.
*/
typedef float (*twoDtype)[2];
twoDtype func3 ( void ) {
static float twoDarray[4][2] = {
{ 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }
};
return twoDarray;
}
void func4 ( void ) {
twoDtype var = func3();
printf( "%f\n", var[1][1] );
}
int main ( ) {
func2();
func4();
return 0;
}
Note that the array is never copied, func2 only has a pointer to the array declared static in func1.