Hi,
I've a function which accpets two integer parameters. Now, after doing some processing within the function I want the two values back. How do I do that? Will return statement be helpful?
Thanks,
Babu
Hi,
I've a function which accpets two integer parameters. Now, after doing some processing within the function I want the two values back. How do I do that? Will return statement be helpful?
Thanks,
Babu
You can send the pointers to the two integers to your funciton. The values will get modified and the changes are also reflected for the rest of the program.
In the middle of difficulty, lies opportunity
If by "I want the two values back" you mean that you will change the values of the arguments and want that to be reflected in the caller, then perhaps you should pass them as pointers.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Yes laserlight, that's what I meant. But why is it not getting reflected when I pass them as values and not the reference ?
Thanks jverkoey! I got it now
Think of it in the piracy sense: if you want a movie these days, you copy it from someone else on the internet and now you have your own local copy of the movie. With this new copy you are free to do whatever you want, and the person who gave it to you doesn't really care or for that matter know about it. This is pass by value.
Flash-back 15 years ago when people borrowed movies from each other: if you accidentally overwrite that ET cassette with your favorite episode of Home Improvement your friend is going to know. This is pass by reference.
wow! That was an excellent analogy! Thanks a lot
It's C, no passing by reference
"jverkoey" nice explaination...