passing 2d and 3d arrays to a function

+1 Josh Arkes · February 2, 2015
Hi there I'm trying to create two 2d and one 3d arrays that using a function. Can you help me to find my mistakes and understand them. Thank you. Here is my code:
// width = 10 ;
// height = 5 ;
// depth = 15 ;
#include <iostream>
using namespace std;
void pass1 (int[][5]) ;
void pass2 (int[][5]) ;
void pass3 (int [] [10] [15]) ;



int main () {

int Array1[10][5] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass1 (Array1);
cout << endl << "pass2 start from here:" << endl ;
int Array2[10][5] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass2 (Array2) ;
cout << endl << "pass3 start form here" << endl ;
int Array3 [5] [10] [15] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass3 (Array3) ;

}
void pass1 (int a[10][5]) 
{
int Array1;
for ( int row = 0 ; row < 10 ; row++)
{
for (int column = 0 ; column < 5 ; column++ ) {
cout << a

Post a Reply

Replies

Oldest  Newest  Rating
0 Jay Deshaun · February 2, 2015
Please use the code BBCode:
<code></code>
"replace < and > with [ and ]"

#include <iostream>
using namespace std;
void pass1 (int[][5]) ;
void pass2 (int[][5]) ;
void pass3 (int [] [10] [15]) ;
// width = 10;
// height = 5;
// depth = 15;


int main () {
int Array1[10][5] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass1 (Array1);

cout << endl << "pass2 start from here:" << endl ;

int Array2[10][5] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass2 (Array2) ;

cout << endl << "pass3 start form here" << endl ;

int Array3[5][10][15] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass3 (Array3) ;
}
void pass1 (int a[10][5]){
int Array1;
for ( int row = 0 ; row < 10 ; row++){
for (int column = 0 ; column < 5 ; column++ ) {
cout << a;
+1 Josh Arkes · February 2, 2015
void pass1 (int a[10][5]) 
{
int Array1;
for ( int row = 0 ; row < 10 ; row++)
{
for (int column = 0 ; column < 5 ; column++ ) {
cout << a
0 Josh Arkes · February 3, 2015
<code>
#include <iostream>
using namespace std;
void pass1 (int[][5]) ;
void pass2 (int[][5]) ;
void pass3 (int [] [10] [15]) ;



int main () {

int Array1[10][5] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass1 (Array1);
cout << endl << "pass2 start from here:" << endl ;
int Array2[10][5] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass2 (Array2) ;
cout << endl << "pass3 start form here" << endl ;
int Array3 [5] [10] [15] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ;
pass3 (Array3) ;

}
void pass1 (int a[10][5]) 
{
int Array1;
for ( int row = 0 ; row < 10 ; row++)
{
for (int column = 0 ; column < 5 ; column++ ) {
cout << a
0 Earl Hudson · February 7, 2015
Wouldn't you need more data in array 3? You have 5 sets of 10 boxes holding 5 values.With the amount of data I see in your code, this is set up as a 2D array.

Something like: 


int Array3 [5] [10] [5] = {
    {1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},
    {1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},
    {1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},
    {1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},
    {1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{1,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7},{,2,3,4,5},{9,8,7,5,9},{8,4,5,3,6},{2,3,4,7,8},{1,2,3,4,5},{6,7,8,9,1},{2,3,4,5,6},{7,8,9,1,2},{3,4,5,6,7},{1,4,6,9,7}
    };
0 Milan Obrenovic · February 7, 2015
@Earl Hudson, that is the worst programming practice i've ever seen by now. Hardcoding arrays is one of the worst things a programmer can do.
0 Earl Hudson · February 8, 2015
The OP supplied his code, I took a shot at answering it in the style he was using. Trying to get across that his :int Array3 [5] [10] [15] = {{1,2,3,4,5},{9,8,7,5,9}, {8,4,5,3,6}, {2,3,4,7,8} ,{1,2,3,4,5} ,{6,7,8,9,1} ,{2,3,4,5,6} ,{7,8,9,1,2}, {3,4,5,6,7}, {1,4,6,9,7}} ; didn't have enough arrays...
  • 1

C++

107,010 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator