Wednesday 2 July 2014

C++ program to pass multidimensional array to a function using pointer


Here is a C++ program to pass multidimensional array to a function using pointer


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
void example(int *p)
{
    cout<<"Array elements : ";
    for(int i=0;i<2;i++)
      for(int j=0;j<3;j++)
        cout<<*(p+i*3+j)<<" ";
}
int main()
{
    int x[2][3]={10,20,30,
                 40,50,60,};
    example(x[0]);
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment