Practice Exercise: Using Variables
Learn about the integer variable, the assignment operator, and the memory allocation.
Swapping the values
Write a program in the code editor below that swaps the values of two variables.
Let’s say we have two variables num1
, which has the value 34
stored, and num2
, which has the value 12
stored. Now we need to swap the values of the two variables such that num1
stores 12
and num2
stores 34
.
Before swapping:
num1: 34
num2: 12
After swapping:
num1: 12
num2: 34
Write your solution in the editor below:
Get hands-on with 1200+ tech skills courses.