Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Simple programming help for pass-by-reference and pass-by-value-result?
I need help with this please.
Write a program, using the syntax of whatever language you like, that produces different behavior depending on whether pass-by-reference or pass-by-value-result is used in its parameter passing.
3 Answers
- DavidLv 68 years agoFavorite Answer
C++:
#include <iostream>
void inc_ref(int& n) // by reference
{
++n;
}
void inc_val(int n) // by value
{
++n;
}
int main()
{
for (int var = 0; var < 10; inc_ref(var))
{
std::cout << var;
}
}
If I had used inc_val inside the for loop parameters, it would cause an infinite loop and a runtime error because merely a copy of var would being incremented.
- ?Lv 44 years ago
would not concern how extensive the lanes for, there's a purpose for it, may be it quite is on a hill or a curve or there's some obstructed view. If a sign says do no longer bypass, it way purely that, that is not substantial what the area. stay in lane, in the lower back of the automobile you're in the lower back of, till at last you come back to an concern in which you will flow them.