I just don't get the C++ Pointer/Reference system.
- by gnm
I've never had problems with references as in Python (implicit) or PHP (explicit &). In PHP you write $p = &$myvar; and you have $p as a reference pointing to $myVar.
So I know in C++ you can do this:
void setToSomething( int& var )
{
var = 123;
}
int myInt;
setToSomething( myInt );
Myint is now 123, why?
Doesn't & mean "memory address of" x in C++? What do I do then if var is only the adress to myInt and not a pointer?
void setToSomething( int* var )
{
var* = 123;
}
int myInt;
int* myIntPtr = &myInt;
setToSomething( myIntPtr );
Does the above work as expected?
I don't understand the difference between * and & in C++ fully. They tell you & is used to get the adress of a variable, but why IN GODS NAME does that help you in functions etc. like in the first example?