Hey guys,
Im reading up on pointers and since i dont have a physical teacher, Its abit hard concept to grasp. Could anyone please explain in their own words shortly how they work, I understand that they carry the adress of another variable, and you'd assign this adress with an '&' sign, but I just cant understand once you have the *p=&b, does it mean that now you work with *p just like with b? and why down the road i see p without asterix sign before it., im confused, anyone could clearify in easiest possible way?
Any help would be greatly appreciated!!!
Rhanx a lot!



8 Years
Discussion Span
Last Post by ArkM
int i;
int *p;

p = &i;   // p holds the address of i

*p = 10;

The last assignment says take the value in p, go to that address and put 10 there.
Therefore, i now holds 10.

To prove that you could print either of these because they are identical.

printf("i is %d", i);      // prints 10
printf("i is %d", *p);  // prints 10
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.