Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
int a = 1;
int b = 2;
a = b;
b = 3;
Console.WriteLine(a);
Console.WriteLine(b);2 3
- Expecting
3 3:a = bcopies the number2intoaand does not tieatob, so changingbafterwards leavesaalone. - Expecting
1 3:=copies the value on its right into the variable on its left, soa = bchangesa, notb.
- What would the program print if the line
b = 3;came beforea = b;? - How would you swap the values of
aandbwith the help of a third variable?