Ah so
I think the source code there is solid.
The pointer does not hold two values at once. Nor does it hold the values 10 or 20 at all or any integer value.
The pointer holds an "adress" to a variable of type int. (Since it was declared as int *)
doing an assignment on *mypointer
is the same as assigning a value
on the variable that "mypointer" points to.
"&firstvalue" is the "adress" of "firstvalue"
so:
1 2
|
mypointer = &firstvalue;
*mypointer = 10;
|
essentially assigns the value 10 to the integer POINTED TO BY (*) "mypointer"
which is firstvalue.
when you assign a new reference or "adress" to mypointer in line 11, it drops the old adress and holds the new one, "&secondvalue"
pointers can be intimidating at first but they are indispensible and you MUST learn how to use them.. especially helpful to return the pointer to the first element of an array from a function
and btw don't be confused by the *
the * in these two lines means two COMPLETELY different and unrelated things:
1 2 3 4 5
|
int i_my_number; // declares an integer
int * p_my_pointer; // declares a POINTER to an integer
p_my_pointer = &i_my_number; // assigns a (REFERENCE to my_number) to my_pointer
*p_my_pointer = 10; // assigns a value of 10 to the integer POINTED TO by my_pointer
cout << i_my_number; // should print number 10
|
why they use the same symbol (*) for declaration of a pointer and dereferencing I don't know but it confused me for a long time. Jus lettin ya know.
All that being said the error is involving other files, not the source you posted.. so I'm not gonna be much help there lol sorry.