Please read before answering. I dont want you to state the obvious for me. THANKS :D
I am trying to differentiate between pointers and passing by value. And I think I understand them but one thing the source I was reading wasnt clear on is what is the difference between passing a pointer and passing by value. consider the following...
andy = 25;
fred = andy;
ted = &andy;
The first line passes the value 25 to andy. The second line passes the value of andy to fred. Now fred possess the value 25. the third line passes reference to ted. Now ted holds the memory address of andy, which holds the value of 25. Now take a look at the next code
andy = 25;
fred = andy;
ted = &andy;
joe = *andy;
The above code looks just like the first snippet except we pass the pointer of andy to joe. Now joe holds the pointer value of 25. Which almost seems the same as just doing (joe = andy). without *
what's the difference in passing the pointer value compared to just passing by value ???
In my interpretation, It appears that the pointer value of joe is still affected if later down the line I decided to change the value of andy/ compared to if I just passed by value, it not be affect. T
To my knowledge, the only difference between passing by reference and passing by pointer is that one holds the address, and the other holds the value within that address. which can still change if any varible that holds that value reference, decides to change it. If this is the case, what is the significance of passing by reference and passing by value.
Here is the link to what I was reading
http://www.cplusplus.com/doc/tutorial/pointers/
Thanks guys!!!