Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   arguments to the function (http://www.go4expert.com/forums/arguments-function-t4033/)

swaeded 26Apr2007 14:38

arguments to the function
 
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 26Apr2007 14:43

Re: arguments to the function
 
What made you think we cannot have something like that.

swaeded 26Apr2007 14:47

Re: arguments to the function
 
So then we cant pass an array as a argument means how to use an arrray in called function

DaWei 26Apr2007 16:18

Re: arguments to the function
 
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 26Apr2007 16:54

Re: arguments to the function
 
Can u give me an example how to pass an array as the argument to the function

DaWei 26Apr2007 18:05

Re: arguments to the function
 
Code:

int matrixDisplay (int a[3][], unsigned size)
{
    ....
}

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



All times are GMT +5.5. The time now is 09:10.