beta.blog

C++ – Pass Two Dimensional Array to Function

by on Nov.04, 2013, under Programming

Short example of how to pass a Two Dimensional Array to a function:

#include <iostream>
using namespace std;

void the_function(char(*arr)[4][4])
{
  // Access the dummy elements like this:
  cout << (*arr)[0][0] << endl; // A
  cout << (*arr)[1][0] << endl; // B
}

int main()
{
  // Create a 4x4 array:
  char arr[4][4];

  // Add some dummy data to the array:
  arr[0][0] = 'A';
  arr[1][0] = 'B';

  // Call the function with a reference to the array:
  the_function(&arr);

  return 0;
}

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!