I initialise 2 arrays like so:
x = (double*) malloc(sizeof(double)*n);
xPlus1 = (double*) malloc(sizeof(double)*n);
Firstly, I'm not certain of exactly what x or xPlus1 now are, a pointer to an array full of doubles, or an array full of pointers to doubles? :/
The answer to that question probably effects this but if I do these various operations, I can't get it to do what I want, which is just to copy the values from xPlus1 into x. xPlus1 and x do hold different values for each index, because printing after a simple for loop achieves the desired effect:
for (int i = 0; i < n; i++) {
x[i] = xPlus1[i];
}
But using...
memcpy(x, xPlus1, sizeof(x));
memcpy(x, &xPlus1, sizeof(x));
If I access x after either of these in the same function, x is unchanged, kept it's old values.
memcpy(&x, &xPlus1, sizeof(x));
I believe this makes x and xPlus1 point to the same memory location by the outputs I get. This is because if I modify x or xPlus1 after this copy, then both values change if I print both arrays.
memcpy(&x, xPlus1, sizeof(x));
Dies, exception: Unhandled exception at 0x011D5626 in MPITemplate.exe: 0xC0000005: Access violation writing location 0x00000000.
The ampersand in functions usually indicate a pass by reference, how does this play out when given to memcpy, and what difference does it make if it's going to write to the same blocks in the end?
I'd appreciate if someone could tell me in detail what's going on with these operations, because I can fiddle around making it work but I'd rather understand what's actually happening when these calls are made.
Thanks,
Mike