|
|
|
|
|
|
double *ptr = x;
Because the array at line 23 goes out of scope when the function returns. You have a pointer to junk. A quick hack is to make it a static array. |
The name of the array x is convertible into a pointer to the first element of the array, with type double*. On the other hand, the expression &x computes the address of the array. It has the incompatible pointer-to-array type double(*)[3]. |
ptr=&x;
didn't seem to have problems as printf("x: %f ", ptr[i]);
printed out the correct values. The problem was with changePtrRef(&ptr);
|
|
|
|
|
|
made sure that ptrX and ptrY each pointed to arrays of length 4, so I thought it would erase the final 4 elements in ptrX and ptrY. |
ptrX[7]
gives the value held in memory at a location that's 7 array-elements-worth of memory after the start of the array. Even if you didn't allocate that memory to be part of the array in the first place.How can I do this since the code above failed to do this? |
|
|
But the line ptr=&x; didn't seem to have problems as printf("x: %f ", ptr[i]); printed out the correct values. |
I thought garbage values should have been outputted for the for i=4 to 7 for ptrX and ptrY |