From: Piotrus S. <pio...@wp...> - 2003-04-26 23:38:06
Hello
Could somebody help me to solve the following problem?
I have to swap two two-dimensional arrays. I wouldn't like to do it in
this way:
...
double vec_1[N][M],vec_2[N][M],temp;
int i,j;
...
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
temp=vec_1[i][j];
vec_1[i][j]=vec_2[i][j];
vec_2[i][j]=temp;
}
...
Thanks for advance. Peter.
From: Ricardo R. <ri...@un...> - 2003-05-02 10:31:21
you dont need to swap the both matrices,
you can easily switch from one matrix to the other
with a pointer, as follows:
**************************************
int matrix1 [ N ] [ M ];
int matrix2[N][M];
int *q = matrix1[0];
matrix1[1][0]=8;
cout << matrix1[1][0] << *(q+3);
q = matrix2[0];
matrix2[1][0]=9;
cout << matrix2[1][0] << *(q+3);
********************************