Initialising 2D and 3D arrays

This is a discussion on Initialising 2D and 3D arrays within the C++ Programming forums, part of the General Programming Boards category; How do u go about initialising 2D and 3D arrays and giving them all values? They are integer values, btw. ...

  1. #1
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128

    Initialising 2D and 3D arrays

    How do u go about initialising 2D and 3D arrays and giving them all values? They are integer values, btw.

    i know " int array[] = { 1 }; " is for 1D arrays of integers, but i cant work out particularly how 3D arrays would be set...

  2. #2
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    int array[5][2] =
    {
    {1,1,1,1,1},
    {1,1,1,1,1}
    };

  3. #3
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    ok thanks.
    what about for 3D arrays?

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I don't think there is a way to initialize a 3D array with starting numbers. I think you have to do them value by value.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by frenchfry164
    I don't think there is a way to initialize a 3D array with starting numbers. I think you have to do them value by value.
    Sure you can. You can initialize any number of dimension of arrays that you can stand to do. (IE: whatever doens't make you go insane while you're typing it all out.

    Here ya go:

    Code:
    int array[2][2][2] =
    {
        {
            {1,2},
            {3,4},
        },
        {
            {5,6},
            {7,8},
        },
    };
    Now you know why I kept it short (ie: 2x2x2).

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    i should be able to work that thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I would like to Produce 2d and 3d plots
    By BobInNJ in forum Windows Programming
    Replies: 2
    Last Post: 03-04-2009, 10:16 PM
  2. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 02:17 PM
  3. 3D to 2D coords....
    By ellis in forum Game Programming
    Replies: 10
    Last Post: 10-18-2006, 12:18 PM
  4. 2d to 3d: Image processing
    By arjunajay in forum C++ Programming
    Replies: 2
    Last Post: 07-19-2006, 10:39 PM
  5. 3D to 2D
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-09-2003, 11:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21