Click here to Skip to main content
13,202,262 members (64,992 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 8 May 2010

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

, 8 May 2010
Rate this:
Please Sign up or sign in to vote.
How to pass a two dimensional array to a function (C++)


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;

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]);


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

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



  return 0;


  • 8th May, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
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...


Comments and Discussions

GeneralMy vote of 1 Pin
Aneet D N29-Sep-14 20:56
memberAneet D N29-Sep-14 20:56 
GeneralTerrible Pin
Member 15069667-Jun-10 6:56
memberMember 15069667-Jun-10 6:56 
GeneralMy vote of 1 Pin
Ali BaderEddin8-May-10 12:44
memberAli BaderEddin8-May-10 12:44 
GeneralRe: My vote of 1 Pin
SledgeHammer019-May-10 7:48
memberSledgeHammer019-May-10 7:48 
GeneralMy vote of 1 Pin
Michel Renaud8-May-10 8:00
memberMichel Renaud8-May-10 8:00 
GeneralMy vote of 1 Pin
SledgeHammer018-May-10 7:20
memberSledgeHammer018-May-10 7:20 
GeneralRe: My vote of 1 Pin
Ali BaderEddin8-May-10 12:41
memberAli BaderEddin8-May-10 12:41 
GeneralRe: My vote of 1 Pin
SledgeHammer019-May-10 7:47
memberSledgeHammer019-May-10 7:47 
GeneralRe: My vote of 1 Pin
Ali BaderEddin10-May-10 9:02
memberAli BaderEddin10-May-10 9:02 
The code in the article should compile fine and is more appropriate when working with 2 dimensional arrays. Reason is you have more details about the parameters from the function signature, so when you call the function you have a better idea how to call it properly. Ever heard of abstraction and encapsulation?

It ain't abstract if you have to look at the underlying implementation to understand what's going on. - P. J. Plauger[^]

If you get what I mean above, I suggest you go ahead and learn more about programming... Learn well and improve your behavior when interacting with others. I can see here that all you're good at is giving votes of 1 to others... Good luck D'Oh! | :doh:
-- Ali B

Generalyou godda be kidding Pin
JohnWallis428-May-10 4:07
memberJohnWallis428-May-10 4:07 
Questionthis is a joke, right? Pin
xliqz8-May-10 2:38
memberxliqz8-May-10 2:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 8 May 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid