Back to questions
JuniorTheoryCommon
What does the program print?
int a = 1;
int b = 1;
Grow(a, ref b);
Console.WriteLine(a + " " + b);
void Grow(int x, ref int y)
{
x = x + 10;
y = y + 10;
}1 11
- Expecting
11 11: only therefparameter changes the caller's variable;xis a copy ofa, soastays1. - Expecting
1 1:refmakesyanother name forb, soy = y + 10changesbitself to11.
- What changes if
bis declared asint b;with no value before the call? - Why does C# require
refin the call as well as in the declaration?