Reputation: 75
Belows are image of STACK that i made to show two methods of assignment. Left one, where return 'indexIndicator' from Find() to main() after procedure of Find() is over. Light one is pointer of pointer(double pointer). I know that both work well, but i want to know which one is preferred and why. Thanks
Upvotes: 2
Views: 195
Reputation: 36391
Well in general, if your function calculates some value you should then use a return; and if your function need to modifies something, you should pass it as a parameter. This rule makes the code easier to read and understand. It is not always easy to follow such a rule, especially when you need to return a bunch of values... Anyway, the semantic of your function should help you.
find()
function generally return the value found, pElement = find(list,criterion);
for example.set()
function generally takes as parameter the value to be
modified, set(&element);
Upvotes: 2