Skip to content

Instantly share code, notes, and snippets.

@Gumball12
Last active October 13, 2019 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gumball12/846b268bc63cb1a76e6f5a9760ecc6f1 to your computer and use it in GitHub Desktop.
Save Gumball12/846b268bc63cb1a76e6f5a9760ecc6f1 to your computer and use it in GitHub Desktop.
swap fucntion
#include <stdio.h>
/**
* swap function
* @param xp pointer x
* @param yp pointer y
* */
void swap(long *xp, long *yp) {
// define temporary values
long temp0 = *xp;
long temp1 = *yp;
// swap values
*xp = temp1;
*yp = temp0;
}
/**
* entry point
* */
int main(void) {
// define values
long x = 10;
long y = 12;
// print values
printf("before swap: %ld %ld\n", x, y);
// swap values
swap(&x, &y);
// print values
printf("after swap: %ld %ld\n", x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment