typestar

Swap via pointers in C

Swapping two values through pointers, the exercise that explains why C has them.

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

Keywords and builtins used here

The run, in numbers

Lines
5
Characters to type
62
Tokens
30
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 20 seconds.

Type this snippet

Step 2 of 5 in Pointers, step 2 of 25 in Pointers & memory.

← Previous Next →