Arrays are EVIL. Use a vector of vectors.
They work similarly to arrays, but have resizing and a bunch of other things, like checking if you don't call for elements outside of the array.
Like this:
#include <vector>
#include <iostream>
using namespace std;
void display(vector<vector<int> > &arr){
// do your stuff here
}
int main(){
vector<vector<int > > arr;
int w,h;
cout<<"Width: ";
cin>>w;
cout<<"Height: ";
cin>>h;
arr.resize(w);
for(int i=0;i<w;i++)
arr[i].resize(h);
// get the array from the user
display(arr);
}
That was the preferred solution.
Another would be to make a 1-dimension array of size w*h, then refer to items like arr[y*cols+h] . But still, it's not recommended, as dynamic allocation is prone to erros, although unaviodable.
Actually, making it one dimension (instead of two) is desirable with vectors too, since with two-dimensional arrays (or array-like classes) there is no assurance that all the numbers will be in one block.
@Behi Jon:
The >> for template class declaration was added in c++ OX, there should be a space in there, like > >