- #1
transgalactic
- 1,395
- 0
when i read about pointers i got the idea that when i want to do a pointer to foo
int foo=35;
i do
i have a problem in understanding this code
&foo is the address of foo not its value
*foo_ptr is a pointer to &foo which is the address
not the variable foo itself
i think the right way to make a pointer to foo is
and now if we execute *foo_ptr=42
we get that &foo=42
the address of foo is now 42
?
int foo=35;
i do
Code:
*foo_ptr=foo; //*foo_ptr returns the value 35
&foo_ptr //has the address of foo
i have a problem in understanding this code
Code:
int foo; //1st line
int *foo_ptr = &foo; //2nd line
int bar = *foo_ptr; //3rd line
*foo_ptr = 42 //4th line
&foo is the address of foo not its value
*foo_ptr is a pointer to &foo which is the address
not the variable foo itself
i think the right way to make a pointer to foo is
Code:
*foo_ptr=foo;
and now if we execute *foo_ptr=42
we get that &foo=42
the address of foo is now 42
?
Last edited: