Last active
October 13, 2019 05:09
-
-
Save Gumball12/846b268bc63cb1a76e6f5a9760ecc6f1 to your computer and use it in GitHub Desktop.
swap fucntion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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