Thread: 3d arrays~

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

    3d arrays~

    Please check this line below, it omits the first dimension, how would the array like this be ???
    PHP Code:
    int myarray[][3][4
    Never end on learning~

  2. #2
    TK
    Guest
    The 3d array gives me a headache, I would have to look that one up, but you can leave the first element in a 2d array if you initialize the array like so.

    Code:
    #include<stdio.h>
    
    int main()
    {
      int array[][3] = {
        {1,2,3},
        {4,5,6},
        {7,8,9},
        {10,11,12}
        };
    
      int i;
      int ii;
    
      for(i=0;i< sizeof(array) / sizeof(array[0]) ; i++)
        {
          for (ii =0; ii < sizeof(array[0]) / sizeof(array[0][0]); ++ii )
            {
              printf("%d ",array[i][ii]);
            }
          printf("\n");
        }
    
      return 0;
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you can omit the first dimension when initialising an array as TK has shown.

    You can also omit the first dimension when declaring an array as an extern.

    extern int myarray[][3][4];

    And you can also omit the first dimension when declaring a function prototype.

    void foo ( int myarray[][3][4] );

  4. #4
    TK
    Guest
    When you declare it with the 'extern' keyword, does this mean that you have to define it in another file?

    If so, than when you define it you have to initialize it in the definiton?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3d graphics without API
    By h3ro in forum Game Programming
    Replies: 6
    Last Post: 05-31-2008, 11:51 AM
  2. A 3D Program for my 3D models...?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 08-19-2004, 10:04 AM
  3. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  4. 3D SDK for C++ programmers
    By chand in forum Game Programming
    Replies: 2
    Last Post: 05-20-2003, 07:38 AM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 11:19 AM