I have 2 questions, may be somewhat noob.
- When I need to pass pointer reference to a function(as arguments) and why?
- When I need to return pointer reference from a function and why?
Thanks a lot
评论:
Aeaex:
CrappyFap69:Do you know what a pointer actually is? Might be better to start there. Have you done the Tour?
0xjnml:Of course I know what pointer is. But I ask the question from ground up to understand everything better
CapableCounteroffer:I think the question stems from the confusion some people have with pointer vs. reference. But the term 'pointer reference' beats that by a long way IMO.
CrappyFap69:When I need to pass pointer reference to a function(as arguments) and why?
An example of why you would want to do this is if you want the function to change what the pointer references. For example, say you have a pointer to an int called i, and it points to the address of something holding the value 5. Then in your function you take its single int argument and add 5 to it. You call the function on i as a value, then you check i. What do you get? i==5. You call the function on i passed as a pointer reference, then you check i. What do you get? i==10 as probably intended.
That's great. Any other reason? And what about the second question?