Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to declare a three dimensional array

How to declare a three dimensional array

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelptutorial
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Danzy83
    wrote on last edited by
    #1

    I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.

    J _ N 3 Replies Last reply
    0
    • D Danzy83

      I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      Maybe this link[^] will help get you started.

      D 1 Reply Last reply
      0
      • J jeron1

        Maybe this link[^] will help get you started.

        D Offline
        D Offline
        Danzy83
        wrote on last edited by
        #3

        I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.

        J L D 3 Replies Last reply
        0
        • D Danzy83

          I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.

          J Offline
          J Offline
          jeron1
          wrote on last edited by
          #4

          OK, how about this[^] site.

          1 Reply Last reply
          0
          • D Danzy83

            I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Try the information here[^]. Although this only covers 2D arrays, you can think of the third dimension as a number of 2D arrays one on top of the other, the index increasing as you go further down the planes.

            It's time for a new signature.

            1 Reply Last reply
            0
            • D Danzy83

              I have been to that site but it only talks about it without examples. I know it can for instance be declared as follows: int rates[10][4][3]; The declaration is what has been shown on the site. But I want to know how to initialise the array when it is declared, and know how the indexing will refer to a particular value in the initialising list.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Dan_K wrote:

              But I want to know how to initialise the array when it is declared...

              Like:

              int Array3D[2][4][6] =
              {
              {
              { 1,2,3,4,5,6 },

                  { 7,8,9,10,11,12 },
              
                  { 13,14,15,16,17,18 },
              
                  { 19,20,21,22,23,24 }
              },
              
              {
                  { 77,78,79,80,81,82 },
              
                  { 83,84,85,86,87,88 },
              
                  { 89,90,91,92,93,94 },
              
                  { 95,96,97,98,99,100 }
              }
              

              };

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Man who follows car will be exhausted." - Confucius

              1 Reply Last reply
              0
              • D Danzy83

                I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #7

                Use boost::multi_array[^] to create arrays of any dimensions.

                «_Superman_»
                I love work. It gives me something to do between weekends.

                Microsoft MVP (Visual C++)

                Polymorphism in C

                1 Reply Last reply
                0
                • D Danzy83

                  I want to know how to declare three dimensional arrays in C/C++ and how they work. Examples will do. Please help.

                  N Offline
                  N Offline
                  norish
                  wrote on last edited by
                  #8

                  A sample;

                  int array[3][4][5] = {
                  { //[0][][]
                  { 1, 2, 3, 4, 5 },//[0][1][]
                  { 1, 2, 3, 4, 5 },//[0][2][]
                  { 1, 2, 3, 4, 5 },//[0][3][]
                  { 1, 2, 3, 4, 5 } //[0][4][]
                  },
                  { //[1][][]
                  { 1, 2, 3, 4, 5 },//[1][1][]
                  { 1, 2, 3, 4, 5 },//[1][2][]
                  { 1, 2, 3, 4, 5 },//[1][3][]
                  { 1, 2, 3, 4, 5 } //[1][4][]
                  },
                  { //[2][][]
                  { 1, 2, 3, 4, 5 },//[2][1][]
                  { 1, 2, 3, 4, 5 },//[2][2][]
                  { 1, 2, 3, 4, 5 },//[2][3][]
                  { 1, 2, 3, 4, 5 } //[2][4][]
                  }
                  };

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups