Error expected ')' trying to pass by reference
<p>I'm trying to count the number of connected 1's in a matrix using a recursive function. Passing the size (max_sz) by reference recursively is giving me problems, but I don't understand why it's saying I'm missing a parenthesis.</p>

<p>I've been looking at this for 30 minutes and have no idea why I'm getting this error. The syntax looks right to me, but I'm a C-beginner so I'm guessing I ran into something I haven't seen before (or I'm just blind).</p>

<p>Here's my code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;


int getval(int (*A)[5], int i, int j, int L, int H) {
    if(i&lt;0 || i&gt;=L || j&lt;0 || j&gt;=H)
        return 0;
    else {
        return A[i][j];
    }
}


void findMaxBlock(int (*A)[5], int r, int c, int L, int H, int size, int **cntarr, int &amp;max_sz){
    if(r&gt;=L || c &gt;=H)
        return;
    cntarr[r][c]=1; 
    size++;
    if(size&gt;max_sz)
        max_sz = size;
    //search in eight directions
    int direction[][2]={{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1}};
    for(int i=0; i&lt;8; i++) {
        int newi = r+direction[i][0];
        int newj = c+direction[i][1];
        int val = getval(A, newi, newj, L, H);
        if(val&gt;0 &amp;&amp; (cntarr[newi][newj]==0)){
            findMaxBlock(A, newi, newj, L, H, size, cntarr, max_sz);
        }
    }
    cntarr[r][c]=0;
}


int** create2darr(int rmax, int colmax) { // In C99, you can use variable-length arrays:        
        int **mat = (int**)malloc(rmax*sizeof(int*));
        for(int i = 0; i &lt; rmax; i++) mat[i] = (int*)malloc(colmax * sizeof(int));
        return mat;
}


int getMaxOnes(int (*A)[5], int rmax, int colmax) {
    int max_sz = 0;
    int size = 0;
    int **cntarr = create2darr(rmax, colmax);
    for(int i=0; i&lt;rmax; i++){
        for(int j=0; j&lt;colmax; j++){
            if(A[i][j] == 1){
                findMaxBlock(A, i, j, rmax, colmax, 0, cntarr, max_sz);
            }
        }
    }
    return max_sz;
}


int main(int argc, char *argv[]) {
    int zarr[][5] = {{1,1,0,0,0},{0,1,1,0,0},{0,0,1,0,1},{1,0,0,0,1},{0,1,1,1,1}};
    printf("Number of maximum 1s are %d\n", getMaxOnes(zarr, 5, 5));
}

/*
11000
01100
00101
10001
01111

ans: 7 (diagonals count too)
*/
</code></pre>

<p>Here are the errors generated:</p>

<pre><code>connected1sInMatrix.c:14:88: error: expected ')'
void findMaxBlock(int (*A)[5], int r, int c, int L, int H, int size, int **cntarr, int &amp;max_sz){
                                                                                       ^
connected1sInMatrix.c:14:18: note: to match this '('
void findMaxBlock(int (*A)[5], int r, int c, int L, int H, int size, int **cntarr, int &amp;max_sz){
                 ^
connected1sInMatrix.c:14:88: error: parameter name omitted
void findMaxBlock(int (*A)[5], int r, int c, int L, int H, int size, int **cntarr, int &amp;max_sz){
                                                                                       ^
connected1sInMatrix.c:19:10: error: use of undeclared identifier 'max_sz'
        if(size&gt;max_sz)
                ^
connected1sInMatrix.c:20:3: error: use of undeclared identifier 'max_sz'
                max_sz = size;
                ^
connected1sInMatrix.c:28:52: error: use of undeclared identifier 'max_sz'
                        findMaxBlock(A, newi, newj, L, H, size, cntarr, max_sz);
                                                                        ^
5 errors generated.
</code></pre>

<p>I know stackoverflow is not a debugger, but I'm completely lost as to what's going on here. Any advice or suggestions is greatly appreciated, thanks. </p>