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. Passing 2-D array in function

Passing 2-D array in function

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
5 Posts 5 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.
  • O Offline
    O Offline
    oRion
    wrote on last edited by
    #1

    How should I implement a 2-D array to be passed into a class function? The following is what I know of passing array. void abc(int a[],int upperlimit) { for (int i =0; i < upperlimit; i++) a[i]= 10; } What changes do I have to make to accomodate a[] to be a 2-D array? If I have not know the size of the 2-d array? Should I use pointer here? I am trying to convert a fortran code which allows for array to be declared as 2-D or 3-D array without specifying the size of the array. Is that possible in VC++ 6.0? :confused:

    N A 2 Replies Last reply
    0
    • O oRion

      How should I implement a 2-D array to be passed into a class function? The following is what I know of passing array. void abc(int a[],int upperlimit) { for (int i =0; i < upperlimit; i++) a[i]= 10; } What changes do I have to make to accomodate a[] to be a 2-D array? If I have not know the size of the 2-d array? Should I use pointer here? I am trying to convert a fortran code which allows for array to be declared as 2-D or 3-D array without specifying the size of the array. Is that possible in VC++ 6.0? :confused:

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      a 2-d array is basically a **. So if you have int ar[10][20] you can prototype the function as :- Fn(int **z); and then you can pass ar as the argument Nish


      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

      1 Reply Last reply
      0
      • O oRion

        How should I implement a 2-D array to be passed into a class function? The following is what I know of passing array. void abc(int a[],int upperlimit) { for (int i =0; i < upperlimit; i++) a[i]= 10; } What changes do I have to make to accomodate a[] to be a 2-D array? If I have not know the size of the 2-d array? Should I use pointer here? I am trying to convert a fortran code which allows for array to be declared as 2-D or 3-D array without specifying the size of the array. Is that possible in VC++ 6.0? :confused:

        A Offline
        A Offline
        Aizik Yair
        wrote on last edited by
        #3

        Nees is right. Now, for your last q. If you put NULL at the and of the array you woudn't need to remember the size of the array. :cool: Aizik Yair Software Engineer

        S 1 Reply Last reply
        0
        • A Aizik Yair

          Nees is right. Now, for your last q. If you put NULL at the and of the array you woudn't need to remember the size of the array. :cool: Aizik Yair Software Engineer

          S Offline
          S Offline
          squizz
          wrote on last edited by
          #4

          Two problems with NULL terminated arrays : - if the array is 2D or 3D, you cannot determine row / column / 'layers' dimensions. - what if one element of the array has a value of 0 (looks like NULL for the compiler) ?

          A 1 Reply Last reply
          0
          • S squizz

            Two problems with NULL terminated arrays : - if the array is 2D or 3D, you cannot determine row / column / 'layers' dimensions. - what if one element of the array has a value of 0 (looks like NULL for the compiler) ?

            A Offline
            A Offline
            Alexandru Savescu
            wrote on last edited by
            #5

            squizz wrote: if the array is 2D or 3D, you cannot determine row / column / 'layers' dimensions. I will answer this before Christian Graus. ;) [pre] Use std::vector > [/pre]and pass a reference to it to the member function. Otherwise, provided that you know the dimension of the 2D array use int f (int** x) Best regards, Alexandru Savescu

            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