Check Your Prediction

When you swap the values of two variables such as x and y, x will have the initial value in y and y will have the initial value in x. If x’s initial value was 6 and y’s was 2 then after the swap x will have a value of 2 and y will have a value of 6.

Run the code below. Does it correctly swap the values?

Run the code below. Does it correctly swap the values?

Q-2: Explain why the code prints what it does. Why doesn’t it swap the values (x and y both have a value of 2 at the end)?

Feedback

Q-3: Please provide feedback here. Please share any comments, problems, or suggestions.

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

What to do next

Click on the following link to go to the post test: Practice Problems

You have attempted 1 of 4 activities on this page