I need help with the following assignment in C# Using the function below, what i
ID: 3886554 • Letter: I
Question
I need help with the following assignment in C#
Using the function below, what is the value of each variable after the line is executed.
void find(ref int a, int b, ref int c)
{
int temp;
c = a * b + 2;
temp = c;
if (b == 0)
a = c / (b + 1);
a = a + c – b;
c = b + temp;
}
one
two
three
int two=2, three=3;
find(ref one, two, ref three);
find(ref two, one, ref three);
find(ref three, two, ref one);
find(ref two, three, ref one);
Using the functions below, what is the value of each variable after the line is executed.
void fun1(ref int a, int b)
{
int intNum1;
intNum1 = b + 12;
a = 2 * b + 5;
b = int1 + 4;
}
void fun2(int u, ref int v)
{
int intNum2;
intNum2 = 6;
v = intNum2 * 4;
}
intNum1
intNum2
int intNum1=1, intNum2=5;
fun1(ref intNum1, intNum2);
fun2(intNum1, ref intNum2);
one
two
three
int two=2, three=3;
find(ref one, two, ref three);
find(ref two, one, ref three);
find(ref three, two, ref one);
find(ref two, three, ref one);
Explanation / Answer
void find(ref int a, int b, ref int c)
{
int temp;
c = a * b + 2;
temp = c;
if (b == 0)
a = c / (b + 1);
a = a + c – b;
c = b + temp;
}
one
two
three
int two=2, three=3;
1
2
3
find(ref one, two, ref three);
3
2
6
find(ref two, one, ref three);
5
1
5
find(ref three, two, ref one);
9
2
10
find(ref two, three, ref one);
7
3
11
void fun1(ref int a, int b)
{
int intNum1;
intNum1 = b + 12;
a = 2 * b + 5;
b = int1 + 4;
}
void fun2(int u, ref int v)
{
int intNum2;
intNum2 = 6;
v = intNum2 * 4;
}
intNum1
intNum2
int intNum1=1, intNum2=5;
1
5
fun1(ref intNum1, intNum2);
17(ref of a is used by intNum1)
5(no reference passwd, value dosent change)
fun2(intNum1, ref intNum2);
1(no reference passwd, value dosent change)
24(ref of v is used by intNum2)
one
two
three
int two=2, three=3;
1
2
3
find(ref one, two, ref three);
3
2
6
find(ref two, one, ref three);
5
1
5
find(ref three, two, ref one);
9
2
10
find(ref two, three, ref one);
7
3
11