Swap two numbers

    Last updated November 30, 2026

    Store a in temp, copy b into a, then copy temp into b. The chart has no decision, because every input takes the same path. FlowSimp is completely free to use — no sign-up required.

    See the flowchart

    What does the flowchart look like?

    Ready to draw?

    No signup. Opens instantly in your browser.

    See the flowchart

    What is the matching code?

    Pseudocode

    read a, b
    temp = a
    a = b
    b = temp

    Python

    def swap(a, b):
        temp = a
        a = b
        b = temp
        return a, b

    C

    void swap(int *a, int *b) {
      int temp = *a;
      *a = *b;
      *b = temp;
    }
    • If a is 3 and b is 8, temp becomes 3, a becomes 8, and b becomes 3.
    • A swap that uses addition or XOR is a different algorithm. This chart is the three-variable swap.