Kodewick
Start learning →
Basic←→0 / 86

Swap the Boxes

#062Basicint t = a; a = b; b = t4 min

Two boxes: a holds 3 and b holds 8. Swap them, so a becomes 8 and b becomes 3. The line that shows them is already written — only the middle steps are missing.

Careful: writing a = b; on its own throws away the 3 that was in a, and it is gone for good.

Should show
8 3
main.cpp
#include <iostream>
using namespace std;

int main() {
    int a = 3;
    int b = 8;
    // your code here: swap the values of a and b
    cout << a << " " << b << endl;
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.