returning a multi dimension array then print it

i cant seem to find a solution to this error
invalid conversion from int to int(*)[9] [-fpermissive]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void PrintSol(int arr[9][9])
{
	for (int i = 0 ; i<9 ; i++)
	{
		for(int j = 0 ; j < 9 ; j ++)
		{
			cout << arr[i][j] << endl;
		}
	}
}
int Grid()
{
	
	int arr[9][9]={
	{0,0,5	,3,0,0	,0,0,0},
	{8,0,0	,0,0,0	,0,0,2},
	{0,7,0	,0,1,0	,5,0,0},

	{4,0,0	,0,0,5	,3,0,0},
	{0,1,0	,0,7,0	,0,0,6},
	{0,0,3	,2,0,0	,0,8,0},
	
	{0,6,0	,5,0,0	,0,0,9},
	{0,0,4	,0,0,0	,0,3,0},
	{0,0,0	,0,0,9	,7,0,0},
	};
	return arr[9][9];
}

int main ()
{
PrintSol(Grid());
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

void PrintSol(int *arr_p)
{
	int (*arr)[9] = (int (*)[9]) (arr_p);
	for (int i = 0 ; i < 9 ; i++)
	{
		for(int j = 0 ; j < 9 ; j ++)
		{
			cout << arr[i][j] << ' ';
		}
		cout << endl;
	}
}

int * Grid()
{
	static int arr[9][9]=
	{
    	{0,0,5	,3,0,0	,0,0,0},
    	{8,0,0	,0,0,0	,0,0,2},
    	{0,7,0	,0,1,0	,5,0,0},

	{4,0,0	,0,0,5	,3,0,0},
    	{0,1,0	,0,7,0	,0,0,6},
    	{0,0,3	,2,0,0	,0,8,0},
	
    	{0,6,0	,5,0,0	,0,0,9},
    	{0,0,4	,0,0,0	,0,3,0},
    	{0,0,0	,0,0,9	,7,0,0},
	};
	
	return &arr[0][0];
}

int main ()
{
   PrintSol(Grid());
}
Last edited on
thnx
Topic archived. No new replies allowed.