Why the following codes don't produce the same results?
declaration (common part)
Code:
double **before, **temp;
before = malloc(N * sizeof(double *));
for ( i = 0; i < M; i++)
{
before[i] = malloc(M * sizeof(double));
}
double **after;
after = malloc(N * sizeof(double *));
for ( i = 0; i < M; i++)
{
after[i] = malloc(M * sizeof(double));
}
First code (we are only interested in before getting the values of after.
Code:
// for each line in the array
for (i = 0; i < n; i++)
{
// for each column in the array
for (j = 0; j < m ; j++)
{
before[i][j] = after[i][j];
}
}
Second try:
Code:
temp = before;
before = after;
after = temp;
The second try seems not to work properly. Why? Shouldn't they produce the same results?