How to pass a vector to a method

Hi everyone, i started to study a bit of C and C++, and i wish that you guys could give me some help :)

I have an exercise that gives this method declaration:
int triangular_inferior(int* mat, int n);

It checks if a matriz is triangular or not. I have the logic, but when i try to pass the parameter it doesnt accept.

Here it goes:

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
int triangular_inferior(int* mat, int n) {
	int linha = 0;
	int coluna = 0;
	for (linha; linha < n; linha++) {
		for (coluna; coluna < n; coluna++) {
			if (coluna > linha && mat[linha*n+coluna] != 0) {
				return 0;
			}
		}
	}
	return 1;	
}

int main(void)
{
	// ExercĂ­cio 20 da lista2_2005
	int matriz_quad[3][3] = {{1,0,0}, {2,2,0}, {2,2,2}};
	
	if (triangular_inferior(matriz_quad, 3)) {
		printf("Triangular, uhuulll!!");
	} else {
		printf("NOT!");
	}

	system("pause" );
	return 0;
}


But it doesnt accept my parameter, it keeps saying: "cannot convert parameter 1 from 'int [3][3]' to 'int *'"

Any sugestions / explanations?

Thank you.
Well, the type int* is a single-dimensional array. You are sending a two-dimensional array. The most logical solution would be to change the first line to:
int triangular_inferior(int** mat, int n) {
Last edited on
i think i cant change the method signature and even if i do change to int** it doesnt work.
Last edited on
Topic archived. No new replies allowed.