arrays declaration and addressing
- by avinash
I have a few straightforward questions:-
Is the following correct according to a normal c++ compiler?
int arr[3][4];
void func(int *a, int m, int n)
{
int i,j;
cin>>i>>j;
cout<< a[i*n + j]; //is this way of addressing correct provided 0<=i<m and 0<=j<n
}
int main()
{
func((int*)arr, 3,4);
}
If the bounds of an array strictly has to be a constant expression, why doesn't the following generate compiler errors?
int func(int m, int n)
{
int arr[m][n]; //m and n are not known until run time
}