Perhaps it has to do with the way you're not initialising the array properly to begin with?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void function1(int arg1);
void function2(double myArray[4][4]);
void function1(int arg1){
double myArray[4][4];
int i = 0, j = 0;
/* initialize array to 0 */
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
myArray[i][j] = 0.0; //!! NOT [4][4]
}
}
function2(myArray);
/* print myArray values */
/* problem: when I print out the resulting values of myArray here, they are wrong. How could they change from being correct within function2(), to being incorrect here? */
/* print again */
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
printf("%f, ", myArray[i][j] );
}
printf("\n");
}
}
void function2(double myArray[4][4]){
/* change values of myArray, and print myArray values; I've verified that *within* this function, the final myArray values *are* correct */
int i = 0, j = 0;
/* assign */
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
myArray[i][j] = i*j;
}
}
/* print */
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
printf("%f, ", myArray[i][j] );
}
printf("\n");
}
}
int main ( ) {
function1(3);
return 0;
}