am still confused about pointers. I have a simple function ,that does some math calculations, called
Code:
void something( int Y, double *Z) {
Y = Y + Z
}
you're passing an int and a double pointer to something(). To access what Z points to, dereference it:
Code:
void something (int Y, double* Z) {
Y = Y + *Z;
}
The problem here is that Y is a new copy in the something function. Y will disappear when your function exits. To use another int from before this function, use a reference:
Code:
void something (int& y, double* z) {
y = y + *z;
}
You might as well use a reference for z, too, since there's no reason to prefer a pointer here.
Code:
void something (int& y, double& z) {
y += z;
}
a += means add what's on the right to the left variable. it's shorter, so people like it over y = y + z.