I want to assign a statically allocated, multi-dimensional array to a temporary variable. Consider the following example:
void foo(int b[3][2])
{
b[1][1] = 1; // no segmentation fault
}
int main()
{
int a[3][2] = {{1, 2}, {11, 12}, {21, 22}};
foo(a);
int** c;
c = (int**)&a;
c[1][1] = 1; // segmentation fault on execution
int* d[3];
d[0] = (int*)&(a[0]);
d[1] = (int*)&(a[1]);
d[2] = (int*)&(a[2]);
d[1][1] = 1; // no segmentation fault
return 0;
}
Basically I want to do what the compiler does with the parameter b of foo(). But the only working solution I could come up with is d. Is there no less complicated way?