C++ – Pass Two Dimensional Array to Function
by admin 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; }