zildjohn01
Programmer
can someone help me understand the & reference operator, such as:
the way i understand this code is, when you access the code it is as it has been declared:
but contains a hidden pointer where the data actually is. so:
is that correct? where should you use & instead of * for reference parameters? is there automatic destruction? documentation/examples on this seemed sparse...
thx in advance
Code:
void MyFunc(int& val) {}
the way i understand this code is, when you access the code it is as it has been declared:
Code:
int x;
but contains a hidden pointer where the data actually is. so:
Code:
void f1(int& data) {data = 7;}
void f2(int data) {data = 7;}
void f3(int *data) {*data = 7;}
void main() {
int x = 5;
f1(x);
// now x == 7 ???
x = 5;
f2(x);
// now x == 5;
x = 5;
f3(&x);
// now x == 7;
}
is that correct? where should you use & instead of * for reference parameters? is there automatic destruction? documentation/examples on this seemed sparse...
thx in advance