Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
int score = 10;
Console.WriteLine(Bonus(score));
Console.WriteLine(score);
int Bonus(int points)
{
points = points * 2;
return points;
}20 10
- Expecting
20 20:pointsis a copy ofscore, so doubling it changes only the copy;Bonusreturns20, andscorestays10. - Expecting
10 10or a compile error: a parameter is an ordinary variable of the method, so it can be assigned, andBonusreturns the new value.
- How would you change the program so that
scoreitself becomes20? - What would the program print if the parameter were named
scoretoo?