Help for three dimensional function call

Discussion in 'C' started by bashamsc, Nov 13, 2007.

  1. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    Please any one can help me regarding function call for three dimensional array.

    How to send result of three dimensional array to main function.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You need to pass the pointer.
     
  3. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    Can u explain me with an example please.
     
  4. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    For any array, say
    Code:
    int arr[2][3][4];
    You can prototype your function as
    Code:
    void foo ( int arr[2][3][4] );
    And define your function as
    Code:
    void foo ( int arr[2][3][4] ) {
      // do stuff with arr[x][y][z]
    }
    
    In other words, copy/paste the declaration of the array you want to pass into the function, into the parameter declaration of that function.

    Note that all these are equivalent.
    Code:
    void foo ( int arr[2][3][4] );
    void foo ( int arr[][3][4] ); // size of major dimension is optional
    void foo ( int (*arr)[3][4] ); // using explicit pointer notation
    



    The call to the function would be just
    Code:
    foo( arr );
    
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Share the code you are having trouble and we can look into it and show you the problem areas.
     

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