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)?

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

Feedback

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

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