Solved

# passing an array to a function

Posted on 2000-03-06

I want to calculate the sum of each row on a 2 dimension array. Also, I need to make it as a function using pointer as argument.But, the function couldn't work. Here is my code:

int **matrix; //matrix is a 2 dimension array.

void row(int **ptr,int n)

main()

{

/*another part of the code go in here to calculate the value of matrix*/

row(matrix,n);

}

void row(int **ptr,int n)

{

int sum_row,x=0,y=0;

for (y=0; y<=n-1;y++)

{

sum_row=0;

for (x=0;x<=n-1;x++)

{

sum_row=sum_row+*(*(ptr+x)+y);

}

printf("The sum of row %d is %d\n", y+1, sum_row);

}

}

Is there anything wrong when I pass the point to the function?

Thank you very much. -Zheng