if i feed pointers to a function and add 1 to them for example, does it change the actual value of the variable the pointer is pointing to? thanx
if i feed pointers to a function and add 1 to them for example, does it change the actual value of the variable the pointer is pointing to? thanx
In order of learned:
HTML - Mastered
CSS - Enough to use
SSI - Mastered
PHP - Advanced
C/C++ - Current Project
if you dereference the pointer and add 1 to that, it will affect the value who's address was passed (so it will change the value outside of the function as well). If you just add to the pointer without dereferencing it, it will NOT affect the pointer outside of the function.
and i dereference it how? sorry im a bit new to this lingo hehe
In order of learned:
HTML - Mastered
CSS - Enough to use
SSI - Mastered
PHP - Advanced
C/C++ - Current Project
dereferencing is when you access the value of the data pointer to by a pointer rather than the memory address of the variable pointed to. You usually do that with the unary operator*
int a; // making an int
int* PointerToAnint = &a; // Making a pointer to an int and initializing it to the address of a
*PointerToAnint = 4; // dereferencing the pointer and setting the value of the variable it points to to 4.
Dereferencing is working with variables, through pointers. Typically, to manipulate variable values with a pointer, you'd do this:
That should print out 16, then 21. I used the 'pMyAge' pointer to manipulate the 'MyAge' variable. This is dereferencing. the line '*pMyAge = 21;' means this:Code:... int MyAge = 16; cout << MyAge << endl; int * pMyAge = &MyAge; *pMyAge = 21; cout << MyAge << endl; ...
"Assign the value of 21 to the variable that 'pMyAge' is pointing to"
[edit] My explanation > Polymorphic's
Last edited by Krak; 01-13-2003 at 09:29 PM.
howdy,
a pointer is an address not a variable, if you add 1 to a pointer it will no longer point to the address it originaly pointed to.if i feed pointers to a function and add 1 to them for example
pointer handling is a subject in itself.
M.R.
Last edited by itld; 01-13-2003 at 09:43 PM.
I don't like you very much. Please post a lot less.
Cheez
*and then*
No, I know you were joking. My point still stands.
When you pass a pointer to a function you can change the original value.
A function can only return one value. So, if you need a function to change two values (say X and Y cooridinates), you can pass-in pointers to both and change both.