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