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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. dynamic two dimentional array

dynamic two dimentional array

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
9 Posts 7 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.
  • K Offline
    K Offline
    KASR1
    wrote on last edited by
    #1

    How to create two dimentional array dynamically?

    P W M 3 Replies Last reply
    0
    • K KASR1

      How to create two dimentional array dynamically?

      P Offline
      P Offline
      pawelzielin
      wrote on last edited by
      #2

      creating two dimensional dynamic array of chars char **array; array = new char*[50]; for (int i =0; i < 50; i++) array[i] = new char[10]; // the new size is [10][50]

      K 1 Reply Last reply
      0
      • P pawelzielin

        creating two dimensional dynamic array of chars char **array; array = new char*[50]; for (int i =0; i < 50; i++) array[i] = new char[10]; // the new size is [10][50]

        K Offline
        K Offline
        krmed
        wrote on last edited by
        #3

        Actually, the new size would be [50][10] with your allocation.

        Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

        P 1 Reply Last reply
        0
        • K KASR1

          How to create two dimentional array dynamically?

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          std::vector< std::vector< char > > MyDynamic2DArray;

          Waldermort

          1 Reply Last reply
          0
          • K KASR1

            How to create two dimentional array dynamically?

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            No need for an array of arrays...

            int (*My500x500Array)[500] = new int[500][500];
            for (int ii = 0; ii < 500; ++ii)
            {
                for (int jj = 0; jj < 500; ++jj)
                {
                    My500x500Array[ii][jj] = jj;
                }
            }
            delete[] My500x500Array;

            Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            C 1 Reply Last reply
            0
            • M Mark Salsbery

              No need for an array of arrays...

              int (*My500x500Array)[500] = new int[500][500];
              for (int ii = 0; ii < 500; ++ii)
              {
                  for (int jj = 0; jj < 500; ++jj)
                  {
                      My500x500Array[ii][jj] = jj;
                  }
              }
              delete[] My500x500Array;

              Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              C Offline
              C Offline
              carrivick
              wrote on last edited by
              #6

              Check the thread subject, In what way is this array dynamic ?

              D M 2 Replies Last reply
              0
              • C carrivick

                Check the thread subject, In what way is this array dynamic ?

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

                carrivick wrote:

                In what way is this array dynamic ?

                The fact that the new and delete operators are present.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                1 Reply Last reply
                0
                • C carrivick

                  Check the thread subject, In what way is this array dynamic ?

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  It's created on the heap?

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  • K krmed

                    Actually, the new size would be [50][10] with your allocation.

                    Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

                    P Offline
                    P Offline
                    pawelzielin
                    wrote on last edited by
                    #9

                    My mistake ;)

                    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