
April 9th, 2009, 07:25 AM
#1
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
what1(arr,6,5) instead of what1(&arr,6,5)
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
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
??

April 9th, 2009, 07:54 AM
#2
Re: double astrix 2D array signature question..
what1(arr,6,5) instead of what1(&arr,6,5)
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?

April 9th, 2009, 11:12 AM
#3
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

Forum Rules

Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.
Featured
