Thread: pass tridimentional arrays

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    pass tridimentional arrays

    Hi, all~

    we know arrays could be passed as arguments but tridimentional arrays looks a bit different from simply arrays. That is, we could implement our function like this:

    Code:
    int myFunction (int arr[][4][5]);
    why the first [] could be blank ?
    Never end on learning~

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >why the first [] could be blank ?
    The function doesn't need the first dimension to determine the size of the array. Simplified, this:

    void func ( int array[10] );
    is equivalent to
    void func ( int *array );

    Notice that the one dimensional array is converted to a simple pointer, so no size information is needed. A multidimensional array however, needs size information for the latter dimensions:

    void func ( int array[10][10] );
    is equivalent to
    void func ( int (*array)[10] );

    The first dimension is still a pointer, but the second is an array reference, it needs a size.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Help with arrays and pointers please...
    By crazyeyesz28 in forum C++ Programming
    Replies: 8
    Last Post: 03-17-2005, 01:48 PM
  4. Pass by reference
    By mcgeady in forum C Programming
    Replies: 11
    Last Post: 02-17-2005, 03:01 AM
  5. sorting arrays
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2001, 05:39 PM