13,398,917 members (34,594 online)
alternative version

#### Stats

42.5K views
3 bookmarked
Posted 8 May 2010

# How to Pass a Two Dimensional Array to a Function (C++)

, 8 May 2010
How to pass a two dimensional array to a function (C++)

## Introduction

Simply define a size of the array in the function header like this:

`void someFunc(int buff[3][2])`

and make a call to the function with another two dimensional array:

```void add(int swap[3][2], int swap2[3][2]) 		/* Function definition 	*/
{
int temp,i;

for (i=0; i<3; i++)
{
temp       = swap[i][0];
swap[i][0] = swap[i][1];
swap[i][1] = temp;
}
return;
}

void display(int array[3][2],int array2[3][2]  ) 	/* Function definition 	*/
{
int count=0,count1=0;

for (count=0;count<3;count++)
for (count1=0;count1<2;count1++)
printf("%d ", array[count][count1]);

printf("\n");
puts("");
}

int main()
{
int i[3][2]=  { {1,2}, {3,4}, {5,6}  };

display(i,i);				/* i is a pointer	*/

display(i,i);

return 0;
}	```

## History

• 8th May, 2010: Initial post

## Share

 Sweden
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

## You may also be interested in...

 Pro

 First Prev Next
 My vote of 1 Aneet D N29-Sep-14 21:56 Aneet D N 29-Sep-14 21:56
 Terrible Member 15069667-Jun-10 7:56 Member 1506966 7-Jun-10 7:56
 Re: My vote of 1 SledgeHammer019-May-10 8:48 SledgeHammer01 9-May-10 8:48
 My vote of 1 Michel Renaud8-May-10 9:00 Michel Renaud 8-May-10 9:00
 My vote of 1 SledgeHammer018-May-10 8:20 SledgeHammer01 8-May-10 8:20
 Re: My vote of 1 Ali BaderEddin8-May-10 13:41 Ali BaderEddin 8-May-10 13:41
 Re: My vote of 1 SledgeHammer019-May-10 8:47 SledgeHammer01 9-May-10 8:47
 Re: My vote of 1 Ali BaderEddin10-May-10 10:02 Ali BaderEddin 10-May-10 10:02
 you godda be kidding JohnWallis428-May-10 5:07 JohnWallis42 8-May-10 5:07
 this is a joke, right? xliqz8-May-10 3:38 xliqz 8-May-10 3:38
 Last Visit: 31-Dec-99 19:00     Last Update: 18-Feb-18 8:22 Refresh 1