#include <iostream>
using namespace std;

void pop(int s, int n)
{
    for (int l = 0; l < n; l++)
    {
        for (int i = 0; i < n; i++)
        {
            cout << s[l][i]  << "\t";
        }
        cout << endl;
    }
}

int main()
{
    int n, num;

    cout << "Enter the Number of matrix -> ";
    cin >> n;

    int s[n][n];

    for (int l = 0; l < n; l++)
    {
        for (int i = 0; i < n; i++)
        {
            s[l][i] = l+i;
        }
    }

    pop(s, n);

    system("pause");
    return 0;
}

need some help with passing multidimensional array to a function.
thanks in advance.

Recommended Answers

All 5 Replies

Here's one version you can try:

void pop(int** s, int n)

i tried that...it din work...thanks...

is din typo for did or slang for did not?

First

int n, num;
    cout << "Enter the Number of matrix -> ";
    cin >> n; 
    int s[n][n];

The n variable needs to be constant, unless your compiler allowed it,
which is not good.

To pass a multidimensional array you need this :

const int FIXED_COL = 5;
void print(int A[][FIXED_COL], int rowSize);

The compiler needs to now the size of the column for a 2d array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.