arguments to the function

Discussion in 'C' started by swaeded, Apr 26, 2007.

  1. swaeded

    swaeded New Member

    Joined:
    Apr 26, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Can we pass a matrix as an argument to a function..
    means can we have the function declaration like this..

    int matrix(int a[j])
    {

    }

    then how can we call this function....
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What made you think we cannot have something like that.
     
  3. swaeded

    swaeded New Member

    Joined:
    Apr 26, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    So then we cant pass an array as a argument means how to use an arrray in called function
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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.
     
  5. swaeded

    swaeded New Member

    Joined:
    Apr 26, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Can u give me an example how to pass an array as the argument to the function
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Code:
    int matrixDisplay (int a[3][], unsigned size)
    {
        ....
    }
    
    int main ()
    {
        myMatrix [4][12] = {....whatever};
        ....
        matrixDisplay (myMatrix [4][], 48);
        ....
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice