arguments to the function

swaeded's Avatar
Light Poster
Can we pass a matrix as an argument to a function..
means can we have the function declaration like this..

int matrix(int a[i][j])
{

}

then how can we call this function....
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
What made you think we cannot have something like that.
swaeded's Avatar
Light Poster
So then we cant pass an array as a argument means how to use an arrray in called function
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You an pass an array as an argument, but not like that. The lowest dimension is the only dimension that may indicated by [], all others must have a constant expression. Furthermore, you are not passing an array, but a pointer to an array. Consequently, you should pass in some size information or expect bounds violations.
swaeded's Avatar
Light Poster
Can u give me an example how to pass an array as the argument to the function
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Code:
int matrixDisplay (int a[3][], unsigned size)
{
    ....
}

int main ()
{
    myMatrix [4][12] = {....whatever};
    ....
    matrixDisplay (myMatrix [4][], 48);
    ....
}