QUOTE
cin>>size>>size1;
function(size,size1);
function(int ,int)
{
int a[size][size1];
}
I'll tell u what i know. Hopefully someone's got a simpler way. I'll give u an example. Suppose ure handling matrices. U ask the user for the order and then ask him to enter each element rowwise. Im gonna use pointers.
CODE
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int row, col; //Stores the order of the matrix
cout<<"Enter Order Of The Matrix"<<endl<<"Rows?";
cin>>row;
cout<<endl<<"Columns?";
cin>>col;
/*Create a pointer that stores the
address of an object which stores the
elements of the matrix*/
int *matrix_pointer;
matrix_pointer = new int[row*col];
int i,j,element_no;
/*Stores the elements of the matrix
rowwise*/
for(i=0;i<row;i++)
{
cout<<"Enter row" <<i+1<<"(Hit Return after each element)"<<endl;
for(j=0;j<col;j++)
{
element_no=i*col+j;
cin>>matrix_pointer[element_no];
}
}
/*prints the elements columnwise*/
for(i=0;i<row;i++)
{
cout<<endl;
for(j=0;j<col;j++)
{
element_no=i*col+j;
cout<<setw(3)<<matrix_pointer[element_no];
}
}
delete [] matrix_pointer;
return 0;
}
In case u didnt know. Multidimensional arrays can have rows and columns. But in memory theyre stored linearly. so with pointers u cannot simply say:
CODE
int *pointer [3][3];
thats why u have:
CODE
matrix_pointer = new int[row*col]
'new' is used to dynamically allocate memory. Its somewhat similar to 'malloc' in C
Also the 'delete' keyword used in the end deallocates memory like 'free' in C.
and while storing/accessing this is what is done:
CODE
element_no=i*col+j
cin>>matrix_pointer[element_no]
where i is ure current row and j is ure current column ( remember ure starting from 0)
Hope u understand.

Check out the C++ tutorials section for more about pointers and dynamic memory allocation in C++.
This post has been edited by Louisda16th: 5 Sep, 2006 - 12:53 AM