Below is our example C file, swap.c, from class today.

#include <stdio.h>

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

int main() {
    int x = 6;
    int y = 3;

    printf("%d %d\n", x, y);
    swap(&x, &y);
    printf("%d %d\n", x, y);


    return 0;
}

Download or copy from /p/cso1/examples/swap.c on the portal.


Copyright © 2023 Daniel Graham, John Hott and Luther Tychonievich.
Released under the CC-BY-NC-SA 4.0 license.
Creative Commons License