CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: double astrix 2D array signature question..

1. Member
Join Date
Jan 2009
Posts
156

## double astrix 2D array signature question..

its a question from a test:
i was asks what what1(arr,6,5) expression will return
??
arr is a 2D array which looks like this:
0 1 1 0 1
0 0 1 0 0
0 0 1 1 1
0 1 0 0 0
1 0 0 1 1
1 0 1 1 0

Code:
```int what1(int **arr, int m, int n){
int i, j, tmp, stam=0;

for(i=0; i<m; i++)
for(j=0; j<n; j++){
tmp = what2(arr,i,j,m,n);
if (tmp>stam)
stam = tmp;
}
return stam;
}

int what2 (int **arr, int row, int col, int m, int n){
int i,j,tmp, stam=0;

if (row < 0 || row >= m || col < 0 || col >= n) return 0;
if (arr[row][col] == 0) return 0;

arr[row][col] = 0;
for(i=-1; i<2; i++)
for(j=-1; j<2; j++){
if(!i && !j) continue;
tmp = 1 + what2(arr, row+i, col+j, m, n);
if (tmp > stam)  stam = tmp;
}
arr[row][col] = 1;

return stam;
}```
why it passes the arr as

can i do arr[0][0] = 0; for arr
if arr is passed instead of &arr
will it save the change after the function ends??

what2
has that line
Code:
`arr[row][col] = 0;`
and i cant decide what happens at the beginning when arr[0][0] = 0;
because arr is passed not &arr
so the change which that line will make
will not exist after what2 ends
??

2. Elite Member Power Poster
Join Date
Oct 2007
Location
Seattle, WA
Posts
10,895

## Re: double astrix 2D array signature question..

You say arr is a 2D array, presumably of type int**. what1 expects an int**. Why would you expect to be passing an int*** instead?

3. Member
Join Date
Jan 2009
Posts
156

## Re: double astrix 2D array signature question..

because
&arr is the way we pass double astrix variable
so we could make changes on the arr itself
??

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•