How to pass a multidimensional array to a function in C and C++

#include <iostream>

// Function prototype
void processArray(int (*arr)[3], int rows, int cols);

int main() {
    const int rows = 2;
    const int cols = 3;

    // Declare and initialize a 2D array
    int myArray[rows][cols] = {{1, 2, 3}, {4, 5, 6}};

    // Call the function and pass the 2D array
    processArray(myArray, rows, cols);

    return 0;
}

// Function definition
void processArray(int (*arr)[3], int rows, int cols) {
    // Access and manipulate the elements of the 2D array
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            std::cout << arr[i][j] << " ";
        }
        std::cout << std::endl;
    }
}